Python 3 reference · List Methods

Python List pop() Method

Remove and return the item at a position, the last item by default. Raises IndexError on an empty list.

Python 3 Since 3.0

Syntax

list.pop(index=-1)

Parameters

ParameterDescription
index optional Position of the item to remove. Default: -1

Return value

The removed item.

Examples

Pop from the end or frontTry it yourself
stack = [1, 2, 3]
print(stack.pop(), stack)
print(stack.pop(0), stack)

Output

3 [1, 2]
1 [2]
Process items until emptyTry it yourself
todo = ["write", "test", "ship"]
while todo:
    print("doing", todo.pop(0))

Output

doing write
doing test
doing ship

Version history

VersionChange
Python 3.0Added