Chapters
Python114 chapters

ReferenceBuilt-in functions

reversed()

Walks a sequence backwards without changing it.

Signature

reversed(sequence)

Parameters

NameMeans
sequenceanything with a length and indexing

Returns

An iterator.

Example

Python
print(list(reversed([1, 2, 3])))
print("".join(reversed("abc")))

original = [1, 2, 3]
list(reversed(original))
print(original)

Output

[3, 2, 1]
cba
[1, 2, 3]

See also