Latest web development tutorials

Python List pop () method

Python list Python list


description

pop () function is used to remove an element in the list (by default the last element), and returns the value of that element.

grammar

pop () method syntax:

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

parameter

  • obj - optional parameter object to remove elements of the list.

return value

This method returns the element object is removed from the list.

Examples

The following example shows the pop () method using the function:

#!/usr/bin/python

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

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

Examples of the above output results are as follows:

A List :  abc
B List :  zara

Python list Python list