Join Regular Classroom : Visit ClassroomTech

reverse() method in Python List

It is a method in list that reverses the original list. The items of the list are reversed. It doesn’t return a value rather it modifies the original list.

Syntax: list_name.reverse()

Let’s make it clear by observing some simple examples:

Example 1

s=[2, 9, 7, 9, 33, 45, 52]
s.reverse()
print(s)

Output:
[52, 45, 33, 9, 7, 9, 2]

Explanation:
Here the elements are in reversed order. Hence the original list is reversed.

Example 2:

s=["Name", "codewindow", "Country", "India"]
s.reverse()
print(s)

Output:
[‘India’, ‘Country’, ‘codewindow’, ‘Name’]

Explanation:

Here the elements of the list are strings. Since we used reverse() method so in output the list is printed in reversed order. Hence the original list is reversed.


You Missed

Also Checkout