How to reverse a Python List

Reverse the elements in a list

The reverse method reverses the elements in a list. It changes the list in place and returns nothing. reverse method has the following syntax.

  • alist.reverse()
    Reverses items in alist in-place.

x = [1, 2, 3] 
x.reverse() 
print x 

The code above generates the following result.





















Home »
  Python »
    Data Types »




Data Types
String
String Format
Tuple
List
Set
Dictionary