Reverse a string · Inverter uma string
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.
Inverter uma string
Devolva a string com seus caracteres de trás para frente: reverse_string("abc") dá "cba".
Slicing do Python tem um truque legal: s[::-1] percorre a string com um passo de -1, do final para o início. Você também pode construir a resposta com um loop se preferir.
Write reverse_string(s) that returns s with its characters in reverse order. A slice s[::-1] does it in one step. · Escreva reverse_string(s) que retorne s com seus caracteres em ordem inversa. Um fatiamento s[::-1] faz isso em um passo.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.