Function Details: reversed

Description


Returns a reverse iterator over the values of the given sequence.


Extended Description


The reversed() function returns a reverse iterator over the values of the given sequence. It works with any object that has a __reversed__() method or supports the sequence protocol (the __len__() method and the __getitem__() method with integer arguments starting at 0). The reversed object returned is an iterator, so it can be used in for loops or converted to other sequence types.


Read More about reversed from Python Documentation

Function Signature


reversed(seq: Sequence) -> Iterator

Module: builtins

Class: reversed

Parameters



Parameter List


  • seq: Sequence

Return


Returns a reverse iterator over the sequence.


Return Type


Iterator

Output

Explanation

These examples show how reversed() works with lists, strings, and tuples.