How to reverse a string in python?

Python provides multiple ways to reverse a string.

Example:


  my_string = 'Python'
  reversed_string = my_string[::-1]
  

Solution:

Using slicing with a step of -1, like my_string[::-1], reverses the string. This is the most idiomatic way to reverse a string in Python.

Beginner's Guide to Python