Python List reverse() Method

Reverses the order of the list

Usage

The reverse() method reverses the order of list.

The method does not return anything; it modifies the list in place.

Syntax

list.reverse()

Examples

Example: Reverse the order of the list

L = ['red', 'green', 'blue']
L.reverse()
print(L)	# ['blue', 'green', 'red']

Example: Reverse the order of the list

L = [1, 2, 3, 4, 5]
L.reverse()
print(L)	# [5, 4, 3, 2, 1]

Access List Items in Reversed Order

If you don’t want to modify the list but access items in reverse order, you can use reversed() built-in function.

It returns the reversed iterator object, with which you can loop through the list in reverse order.

Example: Access list items in reverse order

L = ['red', 'green', 'blue']
for x in reversed(L):
  print(x)
# blue green red