Python List pop() Method

Advertisements


Description

The method pop() removes and returns last object or obj from the list.

Syntax

Following is the syntax for pop() method:

list.pop(obj=list[-1])

Parameters

  • obj -- This is an optional parameter, index of the object to be removed from the list.

Return Value

This method returns the removed object from the list.

Example

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

#!/usr/bin/python

aList = [123, 'xyz', 'zara', 'abc'];

print "A List : ", aList.pop();
print "B List : ", aList.pop(2);

Let us compile and run the above program, this will produce the following result:

A List :  abc
B List :  zara



Advertisements
Advertisements