List Reverse Method in Python

From this tutorial, you will be learning about Python list Reverse method. You will see how to use it on sequences with the help of examples.

Note: The syntax used in the below section is for Python 3. You can change it to any other versions of Python.

Python List Reverse

To Learn about Lists – Read Python List

List Reverse Method

The Reverse method allows you to invert the order of a list of elements. You can use this method to change the priority of sorting order, etc.

Its syntax is as follows:

List_name.reverse()

This method counts the number of instances of an element in a list. See the below example.

How does the Reverse() function work?

This method doesn’t accept any argument and also has no return value. It only creates an updated list which is the reverse of the original sequence.

Please do not confuse the reverse() method with reversed(). The latter allows accessing the list in the reverse order whereas the reverse function merely transposes the order of the elements.

The flowchart below attempts to explain it in a diagram:

Python List Reverse Method Flowchart

Program Examples

Reversing a list of numbers

# Initilize the list of numbers
Cubes = [1,8,27,64,125]
Cubes.reverse()
print (Cubes)

The result is as follows:

[125, 64, 27, 8, 1]

Reversing a list containing strings

# Initialize the list of strings
Mathematics = ["Number Theory", "Game Theory", "Statistics", "Set Theory"]
Mathematics.reverse()
print (Mathematics)

The result is as follows:

['Set Theory', 'Statistics', 'Game Theory', 'Number Theory']

Reversing an empty list

# Initialize an empty list
List = []
List.reverse()
print (List)

The result is as follows:

[]

Best,

TechBeamers