Python reversed() Function
Example
Reverse the sequence of a list, and print each item:
alph = ["a", "b", "c", "d"]
ralph = reversed(alph)
for x in ralph:
print(x)
Try it Yourself »
Definition and Usage
The reversed()
function returns a reversed iterator object.
Syntax
reversed(sequence)
Parameter Values
Parameter | Description |
---|---|
sequence | Required. Any iterable object |
Related Pages
The iter() function returns an iterator object.
The list.reverse() method reverses a List.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.