Reversing a String or List in Python


Reverse strings or lists with slicing.

Source Code

my_string = "hello"
reversed_string = my_string[::-1]
print(reversed_string)

my_list = [1, 2, 3, 4]
reversed_list = my_list[::-1]
print(reversed_list)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments