How to reverse a string in Python?

Better Stack Team
Updated on February 3, 2023

To reverse a string in Python, you can use slicing with the step parameter set to -1. Here is an example:

 
original_string = "hello"
reversed_string = original_string[::-1]
print(reversed_string) # "olleh"
Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →