The reverse() method reverses the elements of the list.
Example
Syntax of List reverse()
The syntax of the reverse() method is:
list.reverse()
reverse() parameter
The reverse() method doesn't take any arguments.
Return Value from reverse()
The reverse() method doesn't return any value. It updates the existing list.
Example 1: Reverse a List
Output
Original List: ['Windows', 'macOS', 'Linux'] Updated List: ['Linux', 'macOS', 'Windows']
There are other several ways to reverse a list.
Example 2: Reverse a List Using Slicing Operator
Output
Original List: ['Windows', 'macOS', 'Linux'] Updated List: ['Linux', 'macOS', 'Windows']
Example 3: Accessing Elements in Reversed Order
If you need to access individual elements of a list in the reverse order, it's better to use the reversed() function.
Output
Linux macOS Windows