Python List reverse() Method


The Python reverse() method reverses the current order of items in a list. The first item becomes the last, the second item becomes the second last, and so on.

The method changes the original list in place. It does not create a new list and it does not sort the values.

Syntax of reverse() 🔝

my_list.reverse()

The reverse() method does not accept any arguments.

Basic reverse() Example 🔝

my_list=['a', 'b', 'c', 'd', 'x', 'y', 'z']

my_list.reverse()

print(my_list)
Output
['z', 'y', 'x', 'd', 'c', 'b', 'a']

The same elements remain in the list, but their positions are reversed.

Reversing a List of Numbers 🔝

The reverse() method works in the same way with numeric lists.

numbers=[1, 2, 3, 4, 5]

numbers.reverse()

print(numbers)
Output
[5, 4, 3, 2, 1]

Reversing a List with Mixed Data Types 🔝

A list can contain different data types, and reverse() can reverse their positions without comparing the values.

my_list=[1, 'apple', 3.14, True]

my_list.reverse()

print(my_list)
Output
[True, 3.14, 'apple', 1]

Because reverse() only changes positions, the elements do not need to be comparable with each other.

Return Value of reverse() 🔝

The reverse() method modifies the existing list and returns None.

my_list=['one', 'two', 'three']

result=my_list.reverse()

print(result)
print(my_list)
Output
None
['three', 'two', 'one']

Do Not Assign reverse() Back to the List

Since reverse() returns None, assigning its return value back to the same variable replaces the list variable with None.

my_list=[1, 2, 3]

my_list=my_list.reverse()

print(my_list)
Output
None

Call reverse() directly when you want to change the existing list.

reverse() vs Sorting in Descending Order 🔝

Reversing a list and sorting a list in descending order are different operations.

The reverse() method only flips the current sequence.

my_list=[4, 2, 9, 1]

my_list.reverse()

print(my_list)
Output
[1, 9, 2, 4]

To arrange values from highest to lowest, use the sort() method with reverse=True.

my_list=[4, 2, 9, 1]

my_list.sort(reverse=True)

print(my_list)
Output
[9, 4, 2, 1]

Therefore, reverse() should not be used when the actual requirement is to sort values in descending order.

reverse() vs List Slicing 🔝

We can also reverse a list by using list slicing with a step value of -1.

my_list=[1, 2, 3, 4]

new_list=my_list[::-1]

print(new_list)
print(my_list)
Output
[4, 3, 2, 1]
[1, 2, 3, 4]

The difference is important:

  • reverse() changes the original list.
  • my_list[::-1] creates a new reversed list and leaves the original list unchanged.

reverse() vs reversed() 🔝

Python also provides the reversed() function. It returns an iterator that reads the items in reverse order without modifying the original list.

my_list=['Alex', 'Ronald', 'John']

new_list=list(reversed(my_list))

print(new_list)
print(my_list)
Output
['John', 'Ronald', 'Alex']
['Alex', 'Ronald', 'John']

Use reverse() when the existing list should be changed. Use reversed() when you want to process the items in reverse order without changing the original list.

Reversing a Nested List 🔝

If a list contains other lists, reverse() reverses only the order of the outer list. It does not automatically reverse the items inside each inner list.

my_list=[
    [1, 2],
    [3, 4],
    [5, 6]
]

my_list.reverse()

print(my_list)
Output
[[5, 6], [3, 4], [1, 2]]

The inner lists keep their own element order. Read more about 2D lists in Python.

Summary of reverse() 🔝

  • reverse() reverses the current order of list items.
  • It does not accept any arguments.
  • It modifies the original list in place.
  • Its return value is None.
  • It does not sort the values.
  • It works with strings, numbers, mixed data types, and nested lists.
  • Use my_list[::-1] when a new reversed list is required.
  • Use reversed() to iterate through items in reverse order without changing the original list.
  • Use sort(reverse=True) when values need to be sorted in descending order.
All List Methods sort() reversed() Questions with Solutions on List




Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer