Python List reverse Function

Python reverse List function is used to reverse a given list. The syntax of the list reverse function is

list_name.reverse()

Python reverse List Function Example 1

The list reverse function reverses the given list items. The below code reverses the elements in an integer list.

# Python List Reverse Function

rList = [10, 190, 120, 180, 120, 105]

rList.reverse()

print("The Items of a Python List in Reverse Order are : \n", rList)

Python List reverse function output

The Items of a Python List in Reverse Order are : 
 [105, 120, 180, 120, 190, 10]

reverse List items Example 2

In this example, we declared a string list. Next, we used the reverse function on it.

TIP: Please refer to List and List methods articles to understand everything about Python Lists.

# Python Reverse List Function

FruitRevList = ['Orange', 'Banana', 'Kiwi', 'Watermelon', 'Grape', 'Blackberry']

FruitRevList.reverse()

print("The Items of a Python List in Reverse Order are : \n", FruitRevList)

Reverse List Items output

The Items of a Python List in Reverse Order are : 
 ['Blackberry', 'Grape', 'Watermelon', 'Kiwi', 'Banana', 'Orange']

List reverse Function Example 3

Let me use this reverse function on Mixed List.

# Reverse List in Python

MixedRevList = ['apple',  1, 5, 'Kiwi', 'Mango']

MixedRevList.reverse()

print("The Items of a Python List in Reverse Order are : \n", MixedRevList)

List reverse function output

The Items of a Python List in Reverse Order are : 
 ['Mango', 'Kiwi', 5, 1, 'apple']

This time, we used the list reverse function on the Nested list (list inside a list).

# Python List Reverse Function

MixedRevList = [[171, 222], [32, 13], [14, 15], [99, 76]]

MixedRevList.reverse()

print("The Items of a Python List in Reverse Order are : \n", MixedRevList)

List reverse function output

The Items of a Python List in Reverse Order are : 
 [[99, 76], [14, 15], [32, 13], [171, 222]]

Python List reverse Example 5

This python program is the same as the first example. However, we are allowing the user to enter the length of a List. Next, we used For Loop to add numbers to the list.

# Python Reverse List Function

intRevList = []

number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, number + 1):
    value = int(input("Please enter the Value of %d Element : " %i))
    intRevList.append(value)

print("The Python List Before Reverse is : ", intRevList)
intRevList.reverse()
print("The Python List After Reverse is  : ", intRevList)
Python Reverse List Function 5

List reverse Example 6

This program allows users to enter their own string or words and then Reverse them

# Python Reverse List Items

strRevList = []

number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, number + 1):
    item = input("Please enter the Value of %d Element : " %i)
    strRevList.append(item)

print("The Python List Before Reverse is : ", strRevList)
strRevList.reverse()
print("The Python List After Reverse is  : ", strRevList)

Reverse List Items output.

Please enter the Total Number of List Elements: 4
Please enter the Value of 1 Element : Apple
Please enter the Value of 2 Element : Kiwi
Please enter the Value of 3 Element : Orange
Please enter the Value of 4 Element : Banana
The Python List Before Reverse is :  ['Apple', 'Kiwi', 'Orange', 'Banana']
The Python List After Reverse is  :  ['Banana', 'Orange', 'Kiwi', 'Apple']