Python list Method - reverse()

htt‮:sp‬//www.theitroad.com

The reverse() method in Python is used to reverse the order of elements in a list. The method modifies the original list in place and does not return anything.

The syntax for the reverse() method is as follows:

list.reverse()

Here, list refers to the list to be reversed.

Example:

# Creating a list
my_list = [1, 2, 3, 4]

# Reversing the list
my_list.reverse()

# Displaying the modified list
print(my_list)   # Output: [4, 3, 2, 1]

In the above example, the reverse() method is used to reverse the order of elements in the list my_list. The original list is modified and the output shows the updated list. It is important to note that the reverse() method does not create a new reversed list, but it modifies the original list in place.