Python3 reversed Function
Description
The reversed function returns a reversed iterator.
Syntax
The following is the syntax of reversed:
reversed(seq)
Parameters
- seq -- The sequence to be converted, which can be a tuple, string, list, or range.
Return Value
Returns a reversed iterator.
Examples
The following shows examples using tuples:
Examples
#!/usr/bin/env python3
# String
seqString = 'Example'
print(list(reversed(seqString)))
# Tuple
seqTuple = ('R', 'u', 'n', 'o', 'o', 'b')
print(list(reversed(seqTuple)))
# range
seqRange = range(5, 9)
print(list(reversed(seqRange)))
# List
seqList = [1, 2, 4, 3, 5]
print(list(reversed(seqList)))
The output of the above examples is:
['b', 'o', 'o', 'n', 'u', 'R'] ['b', 'o', 'o', 'n', 'u', 'R'] [8, 7, 6, 5] [5, 3, 4, 2, 1]Other Extensions
Python3 Built-in Functions