Reverse a string
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
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.
Write reverse_string(s) that returns s with its characters in reverse order. A slice s[::-1] does it in one step.
Click Run to see the output here.