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

Python List reverse() method

Python List reverse() method

Python Lists Python Lists


Description

The reverse() function reverses the elements in a list.

Syntax

reverse() method syntax:



list.reverse()

Parameters

Return Value

This method has no return value, but reverses the order of the list's elements.

Example

The following example shows how to use the reverse() function:

Example

#!/usr/bin/python

aList

=

[

123

,

'xyz'

,

'zara'

,

'abc'

,

'xyz'

]

aList.

reverse

(

)

print

"List : "

,

aList

The output of the above example is:



List :  ['xyz', 'abc', 'zara', 'xyz', 123]

Python Lists Python Lists