← Back to Gists

Reverse a string

📝 Python
deanna_avila
deanna_avila · Level 4 ·

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

Slicing creates a new string, it does not reverse in place. Strings are immutable.