Reverse a string · Invertir una cadena
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.
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.
Write reverse_string(s) that returns s with its characters in reverse order. A slice s[::-1] does it in one step. · Escribe reverse_string(s) que devuelva s con sus caracteres en orden inverso. Un corte s[::-1] lo hace en un solo paso.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.