ordering

list.reverse

Reverses the elements of the list in place. Returns None; O(n) time and O(1) extra space.

list.reverse()

Parameters

Parameter Purpose
(no args) reverse() takes no arguments.
vs. lst[::-1] Slicing with ::-1 returns a new reversed list without touching the original.

Examples

>>> lst = [1, 2, 3]
>>> lst.reverse()
>>> lst
[3, 2, 1]

In-place reversal.

>>> lst = [1, 2, 3]
>>> lst[::-1]
[3, 2, 1]
>>> lst
[1, 2, 3]

Slice copy leaves the original unchanged.

>>> lst = [1, 2, 3]
>>> list(reversed(lst))
[3, 2, 1]

reversed() returns an iterator — cheaper if you only need one pass.

>>> [].reverse()
>>> 

Safe on empty lists; no exception.

Gotcha

reverse() returns None (like sort). Use lst[::-1] for a new list or reversed(lst) for a lazy iterator when you must not mutate the original.

Related methods

← All Python list methods · Dict methods · list vs tuple vs set