Easy Tutorial
❮ Python Clear List Python 99 Table ❯

Python3 reversed Function

Python3 Built-in Functions


Description

The reversed function returns a reversed iterator.

Syntax

Here is the syntax for reversed:

reversed(seq)

Parameters

Return Value

Returns a reversed iterator.


Examples

Below are examples using tuples:

#!/usr/bin/env python3

# String
seqString = 'tutorialpro'
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:

['o', 'r', 'o', 'p', 'l', 'a', 't', 'u', 't']
['b', 'o', 'o', 'n', 'u', 'R']
[8, 7, 6, 5]
[5, 3, 4, 2, 1]

Python3 Built-in Functions

❮ Python Clear List Python 99 Table ❯