Python List – reverse()
Python list.reverse() method reverses the order of elements in this list, in place. in place meaning, reverse() method modifies the original list.
ADVERTISEMENT
Syntax
The syntax to call reverse() method on a list myList
is
myList.reverse()
where
myList
is a Python listreverse
is method name
Examples
Reverse a List
In the following program, we initialize a list myList
with some elements. We shall reverse the order of elements in this list, using reverse()
method.
main.py
#take a list myList = ['apple', 'banana', 'cherry'] print(f'original list : {myList}') #reverse the list myList.reverse() print(f'reversed list : {myList}')Try Online
Output
original list : ['apple', 'banana', 'cherry'] reversed list : ['cherry', 'banana', 'apple']
Conclusion
In this Python Tutorial, we learned how to reverse the order of elements in a list using list.reverse() method.