Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

list.reverse

Reverses the order of a list in place.

Version: Python 3.14; repository image, production runtime not attested

Syntax

a.reverse()

Reverses the order of a list in place.

A reference to the same list observes the changed order, and the method itself returns None.

Reverses the actual list without creating a reversed list as the return value. The call therefore prints None and the alias shows [5, 8, 2]. No comparisons between elements are needed to reverse their positions.

a = [1, 2, 3]
b = a
assert a.reverse() is None and b == [3, 2, 1]

Examples

a = [2, 8, 5]
alias = a
print(a.reverse())
print(alias)

Result

None
[5, 8, 2]

Reverses the actual list without creating a reversed list as the return value. The call therefore prints None and the alias shows [5, 8, 2]. No comparisons between elements are needed to reverse their positions.

Sources