Skip to content · ⁨Saltar al contenido⁩

Reverse a string · ⁨Invertir una cadena⁩

English

Reverse a string

Return the string with its characters back-to-front: reverse_string("abc") gives "cba".

Python slicing has a neat trick: s[::-1] walks the string with a step of -1, from the end to the start. You can also build the answer with a loop if you prefer.

Español

Invertir una cadena

Devuelve la cadena con sus caracteres en orden inverso: reverse_string("abc") devuelve "cba".

El rebanado de Python tiene un truco muy útil: s[::-1] recorre la cadena con un paso de -1, desde el final hasta el principio. También puedes construir la respuesta utilizando un bucle si lo prefieres.

Log in or create account · ⁨Iniciar sesión o crear cuenta⁩

IGCSE, A-Level & AP