Python List reverse() Method


Advertisements


Description

The method reverse() reverses objects of list in place.

Syntax

Following is the syntax for reverse() method −

list.reverse()

Parameters

  • NA

Return Value

This method does not return any value but reverse the given object from the list.

Example

The following example shows the usage of reverse() method.

Live Demo
#!/usr/bin/python

aList = [123, 'xyz', 'zara', 'abc', 'xyz'];
aList.reverse();
print "List : ", aList

When we run above program, it produces following result −

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

python_lists.htm

Advertisements