Python reversed() Function
Returns a reversed iterator object.
Syntax
Python
Copy Code
reversed(sequence)
Parameters
Parameter | Description |
---|---|
sequence |
Required. Any sequence of objects that supports either the sequence protocols
(__len__() and __getitem__() ) such as tuple ,
string , list etc, or an object that implements
__reverse__() .
|
Example
Python
Copy Code
range10to15 = range(10, 15) reversedRange = reversed(range10to15) for n in reversedRange: print(n)
Output
14 13 12 11 10