Skip to content

Reverse a 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.

Log in or create account

IGCSE & A-Level