Python 3 reference · List Methods
Python List reverse() Method
Reverse the order of the items in place. Returns None; use reversed() or slicing for a reversed copy.
Python 3 Since 3.0
Syntax
list.reverse()
Return value
None.
Examples
steps = [1, 2, 3]
steps.reverse()
print(steps)
Output
[3, 2, 1]
nums = [1, 2, 3]
print(nums[::-1], list(reversed(nums)), nums)
Output
[3, 2, 1] [3, 2, 1] [1, 2, 3]
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
list.sort()· Sort the list in place, optionally by a key function and in reverse. Returns None; sorted() returns a new list.reversed()· Return an iterator that goes through a sequence backwards, without copying it. Works on lists, tuples, strings and ranges.- Python Lists · tutorial