How to Reverse a String in Python


In this example, we will learn how to reverse a string using functions in Python.

Source Code

def my_function(x):
    return x[::-1]

my_string = 'I love Python'
my_string_reverse = my_function(my_string)
print(my_string_reverse)

Output:

nohtyP evol I
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement