Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python List pop() method

Python List pop() method

Python Lists Python Lists


Description

The pop() function removes an element from a list (the last element by default) and returns its value.

Syntax

pop() method syntax:



list.pop([index=-1])

Parameters

Return Value

This method returns the element object removed from the list.

Example

The following example shows how to use the pop() function:

Example

#!/usr/bin/python3

#coding=utf-8

list1

=

[

'

Google

'

,

'

Runoob

'

,

'

Taobao

'

]

list_pop

=

list1

.

pop

(

1

)

print

"

The removed item is:

"

,

list_pop

print

"

The list is now:

"

,

list1

The output of the above example is:



删除的项为 : Runoob

列表现在为 :  ['Google', 'Taobao']

Python Lists Python Lists