Reverse a string
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
This one builds on a lesson you haven't finished yet. Do that lesson first:
Python Basics · Functions →
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.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
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.