← Back to Gists

Reverse a string

📝 Python
deanna_avila
deanna_avila · 4d ago
This Python snippet reverses a string in place using slicing with a step of negative one.
Python
def reversestring(s): return s[::-1]

Comments

0
aellis aellis 4d ago
Slicing creates a new string, it does not reverse in place. Strings are immutable.