Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 reversed Function

Python3 reversed Function

Python3 Built-in Functions Python3 built-in function


Description

The reversed function returns a reversed iterator.

Syntax

The syntax of reversed is as follows:


reversed(seq)

Parameters

Return Value

Returns a reversed iterator.


Example

The following shows an example using a tuple:

Example

#!/usr/bin/env python3

String

seqString

=

'

Runoob

'

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 example is:


['b', 'o', 'o', 'n', 'u', 'R']
['b', 'o', 'o', 'n', 'u', 'R']
[8, 7, 6, 5]
[5, 3, 4, 2, 1]

Python3 Built-in Functions Python3 built-in function