Skip to content · ⁨Pular para o conteúdo⁩

Reverse a string · ⁨Inverter uma string⁩

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.

Português

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.

Log in or create account · ⁨Entrar ou criar conta⁩

IGCSE, A-Level & AP