Python List pop() Method
Description
The pop() function is used to remove an element from a list (the last element by default) and return the value of that element.
Syntax
The syntax of the pop() method is:
list.pop([index=-1])
Parameters
- obj -- Optional parameter. The index of the list element to remove. It must not exceed the total length of the list. The default is index=-1, which removes the last list value.
Return Value
This method returns the element object removed from the list.
Example
The following example demonstrates how to use the pop() function:
Example
#!/usr/bin/python3
#coding=utf-8
list1 = ['Google', 'Example', 'Taobao']
list_pop=list1.pop(1)
print "The deleted item is:", list_pop
print "The list is now:", list1
The output of the above example is:
删除的项为 : Example 列表现在为 : ['Google', 'Taobao']Other Extensions
Python List