Python List reverse() Method

Python 列表Python List


Description

The reverse() function is used to reverse the elements in a list.

Syntax

Syntax of the reverse() method:

list.reverse()

Parameters

  • NA。

Return Value

This method has no return value, but it reverses the order of the elements in the list.

Example

The following example demonstrates the usage of 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 as follows:

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

Python 列表Python List

Other Extensions