|
| Home |
|---|
The Python list reverse() method is used to reverse the order of elements in a list. It changes the position of every element so that the last element becomes the first, the second-last element becomes the second, and the first element becomes the last.
The reverse() method is particularly useful when you need to
process or display the elements of a Python list in the opposite order
without sorting them.
An important feature of list.reverse() is that it
modifies the original list in place. It does not create a
new list, and the method returns None.
In this tutorial, you will learn how to use the Python
reverse() method, understand its syntax, reverse lists of
numbers and strings, understand reverse() versus
reversed(), compare reverse() with list slicing
and sort(), and learn common mistakes made by beginners.
The reverse() method reverses the current order of elements in
a Python list. It does not sort the elements and does not change their
values.
For example, consider this list:
numbers = [10, 20, 30, 40]
After calling:
numbers.reverse()
the list becomes:
[40, 30, 20, 10]
Notice that the values themselves have not been changed. Their positions have been reversed.
This is different from sorting. Sorting arranges elements according to
their values, while reverse() simply reverses the order in
which the elements currently appear.
The simplest way to reverse a Python list is to call
reverse().
numbers = [10, 20, 30, 40]
numbers.reverse()
print(numbers)
[40, 30, 20, 10]
The first element, 10, moves to the last position, while the
last element, 40, becomes the first element.
The reverse() method works with lists containing strings as
well as numbers.
fruits = ["apple", "banana", "cherry"]
fruits.reverse()
print(fruits)
['cherry', 'banana', 'apple']
The method reverses the order of the strings. It does not sort them alphabetically.
You can use reverse() to process a list of names from the last
name to the first name.
students = ["Ali", "Sara", "John", "David"]
students.reverse()
print(students)
['David', 'John', 'Sara', 'Ali']
This can be useful when processing records in reverse order or displaying recent items before older items.
A list does not need to be created manually before using
reverse(). You can create the list dynamically and then
reverse it.
numbers = []
for i in range(1, 6):
numbers.append(i)
numbers.reverse()
print(numbers)
[5, 4, 3, 2, 1]
The loop first creates the list [1, 2, 3, 4, 5]. The
reverse() method then changes its order to
[5, 4, 3, 2, 1].
The reverse() method can be used with a list containing
Boolean values as well.
values = [True, False, True, False]
values.reverse()
print(values)
[False, True, False, True]
The method simply changes the order of the elements. It does not change
True into False or vice versa.
A Python list can contain different types of objects, and
reverse() can reverse their positions without comparing their
values.
items = [10, "Python", True, 25.5]
items.reverse()
print(items)
[25.5, True, 'Python', 10]
This is different from sorting, because reversing a list does not require Python to compare the elements with one another.
Yes. The reverse() method changes the original list directly.
This is known as an in-place operation.
numbers = [1, 2, 3, 4]
numbers.reverse()
print(numbers)
[4, 3, 2, 1]
The variable numbers still refers to the same list, but the
order of its elements has been changed.
The reverse() method returns None. It does not
return the reversed list.
numbers = [1, 2, 3]
result = numbers.reverse()
print(result)
print(numbers)
None
[3, 2, 1]
The reversed list is stored in the original variable
numbers. The variable result contains
None.
A common beginner mistake is expecting reverse() to return a
new list.
For example:
numbers = [1, 2, 3]
reversed_numbers = numbers.reverse()
print(reversed_numbers)
The output is:
None
Instead, use:
numbers = [1, 2, 3]
numbers.reverse()
print(numbers)
If you need a separate reversed list, use reversed() or list
slicing.
Sometimes you need the reversed version of a list while keeping the
original list unchanged. In that situation, do not use
list.reverse() directly.
One simple option is list slicing using [::-1].
numbers = [1, 2, 3, 4]
reversed_numbers = numbers[::-1]
print(reversed_numbers)
print(numbers)
[4, 3, 2, 1]
[1, 2, 3, 4]
The slicing expression creates a new list in reverse order, leaving the original list unchanged.
Python also provides the built-in reversed() function.
Unlike list.reverse(), the reversed() function
does not modify the original list.
numbers = [1, 2, 3, 4]
reversed_numbers = list(reversed(numbers))
print(reversed_numbers)
print(numbers)
[4, 3, 2, 1]
[1, 2, 3, 4]
The reversed() function returns a
reverse iterator. Using list() converts that
iterator into a new list.
| Feature | reverse() | reversed() |
|---|---|---|
| Type | List method | Built-in function |
| Original list | Modified | Not modified |
| Return value | None |
Reverse iterator |
| Creates a new list? | No | Not by itself |
| Can be used in iteration? | Not directly | Yes |
numbers = [1, 2, 3]
numbers.reverse()
print(numbers)
[3, 2, 1]
Here, reverse() changes the original list.
With reversed():
numbers = [1, 2, 3]
print(list(reversed(numbers)))
print(numbers)
[3, 2, 1]
[1, 2, 3]
The original list remains unchanged.
Both reverse() and [::-1] can be used to obtain a
list in reverse order, but they behave differently.
| Method | Changes Original List? | Creates New List? |
|---|---|---|
list.reverse() |
Yes | No |
list[::-1] |
No | Yes |
list(reversed(list)) |
No | Yes |
The reverse() and sort() methods are both Python
list methods, but they perform completely different operations.
| Feature | reverse() | sort() |
|---|---|---|
| Purpose | Reverses the current order | Sorts elements according to their values |
| Changes original list? | Yes | Yes |
| Returns a list? | No | No |
| Parameters | None | key, reverse |
Suppose the list is:
numbers = [30, 10, 40, 20]
Using reverse():
numbers.reverse()
produces:
[20, 40, 10, 30]
The existing order has simply been reversed.
Using sort():
numbers.sort()
produces:
[10, 20, 30, 40]
The values have been arranged numerically.
Another common beginner mistake is assuming that
reverse() and sort(reverse=True) do the same thing.
They do not.
Consider:
numbers = [30, 10, 40, 20]
Using:
numbers.reverse()
produces:
[20, 40, 10, 30]
But:
numbers.sort(reverse=True)
produces:
[40, 30, 20, 10]
reverse() reverses the existing order, whereas sort(reverse=True) sorts the values from largest to smallest.
A reversed list can be processed with a for loop after calling
reverse().
numbers = [1, 2, 3, 4, 5]
numbers.reverse()
for number in numbers:
print(number)
5
4
3
2
1
This is useful when a program needs to process list elements from the last element toward the first.
If you want to loop through a list in reverse order while preserving the
original list, reversed() is often convenient.
numbers = [1, 2, 3, 4, 5]
for number in reversed(numbers):
print(number)
print(numbers)
5
4
3
2
1
[1, 2, 3, 4, 5]
This approach is useful when you only need to process the elements in reverse order and do not want to modify the list.
Calling reverse() on an empty list does not produce an error.
The list simply remains empty.
numbers = []
numbers.reverse()
print(numbers)
[]
A list containing only one element also remains unchanged because there is no second element to change its position with.
numbers = [100]
numbers.reverse()
print(numbers)
[100]
The reverse() method also works normally when a list contains
duplicate elements.
numbers = [1, 2, 2, 3, 4, 2]
numbers.reverse()
print(numbers)
[2, 4, 3, 2, 2, 1]
The duplicate values are not changed or removed. Their positions are simply reversed along with the rest of the list.
A Python list can contain other lists. The reverse() method
reverses the order of the inner list objects, but it does not reverse the
contents of each inner list.
numbers = [[1, 2], [3, 4], [5, 6]]
numbers.reverse()
print(numbers)
[[5, 6], [3, 4], [1, 2]]
Notice that [1, 2] itself has not become
[2, 1]. Only the order of the outer list has been reversed.
If you need to reverse the contents of each nested list as well, you must perform an additional operation.
numbers = [[1, 2], [3, 4], [5, 6]]
for row in numbers:
row.reverse()
print(numbers)
[[2, 1], [4, 3], [6, 5]]
Here, reverse() is called separately on every inner list.
Python list slicing provides another concise way to create a reversed copy of a list.
numbers = [1, 2, 3, 4, 5]
reversed_numbers = numbers[::-1]
print(reversed_numbers)
Output:
[5, 4, 3, 2, 1]
The ::-1 slice means that Python traverses the list using a
step of -1.
Use the reverse() method when you have a list and want to
change its existing order directly.
Common situations include:
Use reversed() when you want to traverse an object in reverse
order without modifying the original list.
For example:
for item in reversed(items):
print(item)
This is particularly useful when you only need reverse-order iteration.
Use [::-1] when you want a new reversed list and prefer the
concise Python slicing syntax.
reversed_items = items[::-1]
The original list remains unchanged.
Reversing a list requires Python to process the elements in the list.
Therefore, the time complexity of list.reverse() is
O(n), where n is the number of elements in the
list.
The operation is performed in place, so reverse() does not
require creating a separate list containing the reversed elements.
For most everyday Python programs, reverse() is an efficient
way to reverse an existing list.
The reverse() method has a wide range of practical uses in
Python programming.
The reverse() method returns None. It modifies the
original list instead.
reverse() is a list method that changes the list.
reversed() is a built-in function that returns a reverse
iterator without modifying the original list.
reverse() simply reverses the current order. It does not sort
the values.
If you need to preserve the original order, use
reversed() or [::-1] instead.
If the list is not already sorted and you need values from largest to smallest, use:
numbers.sort(reverse=True)
Do not assume that:
numbers.reverse()
will produce descending numerical order. It only reverses whatever order the list already has.
reverse() is a method of Python lists.list.reverse().reverse() reverses the current order of list elements.None.reversed() when you do not want to modify the original list.[::-1] when you want a reversed copy using slicing.sort(reverse=True) when you need descending sorted order.
The reverse() method is a Python list method that reverses the
order of elements in the original list.
Call the reverse() method on the list:
numbers = [1, 2, 3, 4]
numbers.reverse()
print(numbers)
The result is [4, 3, 2, 1].
The syntax is:
list.reverse()
The method does not require any arguments.
Yes. reverse() changes the original list directly. It is an
in-place list operation.
The reverse() method returns None. The original
list itself is modified.
You can use list slicing:
reversed_list = numbers[::-1]
Or use:
reversed_list = list(reversed(numbers))
reverse() modifies the original list and returns
None. reversed() returns a reverse iterator and
does not modify the original list.
reverse() changes the current order of elements, while
sort() arranges elements according to their values.
reverse() reverses the existing order. The
sort(reverse=True) operation sorts the values into descending
order.
Yes. The reverse() method works with lists containing strings
and reverses their positions.
Yes. Calling reverse() on an empty list leaves the list as
[].
Yes. Duplicate elements are handled normally. Their positions are reversed along with the other elements.
The time complexity of list.reverse() is
O(n), where n is the number of elements in the
list.
No. The reverse() method modifies the existing list in place.
If you need a new reversed list, use [::-1] or convert the
result of reversed() to a list.
Struggling with Python syntax, assignments or debugging errors? Learning alone can be frustrating.
Get 1-on-1 Python tutoring and learn faster with clear explanations, real examples and live help.
Home Tutorial Online Live Trainings Contact Us © 2026 All rights reserved by www.PythonTutor.net