Python List - reverse

The reverse method inverses the ordering of the elements present in the python list object

List Updated 15 Sep 2016 1 min read

Method Name

reverse

Method Signature

reverse()

Method Overview

  • This method reverses the ordering of the elements in a Python list object.

Parameters and return value

Reversing of operation happens in-place and the method does not return any value.

Example

python
# Example Python program that reverses the order of elements

            # present in a Python list object

            cityList = ["Dublin", "London", "Paris", "Brussels", "Amsterdam", "Berlin", "Warsaw"]

            print("List of cities:");

print(cityList)

            cityList.reverse()

print("List of cities in reverse order:");

            print(cityList)

Output

Output
List of cities:

['Dublin', 'London', 'Paris', 'Brussels', 'Amsterdam', 'Berlin', 'Warsaw']

List of cities in reverse order:

['Warsaw', 'Berlin', 'Amsterdam', 'Brussels', 'Paris', 'London', 'Dublin']