Skip to content · ⁨Passer au contenu⁩

Reverse a string · ⁨Inverser une chaîne⁩

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.

Français

Inverser une chaîne

Retournez la chaîne avec ses caractères à l'envers : reverse_string("abc") donne "cba".

La tranchage Python a un petit tour : s[::-1] parcourt la chaîne avec un pas de -1, de la fin vers le début. Vous pouvez aussi construire la réponse avec une boucle si vous préférez.

Log in or create account · ⁨Se connecter ou créer un compte⁩

IGCSE, A-Level & AP