Python Basics

How to reverse a string in python?

In certain situation, you may want to reverse the string using Python programming language. Following is the right way to do it.

Reverse a string in python

In python, there is no in built function available which can reverse a string. However we can use slice in backwards to print the string in the reverse.

Solution: [::-1]

Example:

str=”orange”

print(str[::-1])

Output: egnaro