Python List pop() Method

Removes an item at specified index

Usage

The pop() method removes a single list item at specified index and returns it.

If no index is specified, pop() method removes and returns the last item in the list.

Syntax

list.pop(index)

Python list pop() method parameters
ParameterConditionDescription
indexOptionalAn index of item you want to remove.
Default value is -1

Return Value

The pop() method returns the value of removed item.

Examples

Example: Remove 2nd list item

L = ['red', 'green', 'blue']
L.pop(1)
print(L)	# ['red', 'blue']

You can also use negative indexing with pop() method.

Example: Remove 2nd list item with negative indexing

L = ['red', 'green', 'blue']
L.pop(-2)
print(L)	# ['red', 'blue']

When you remove an item from the list using pop(), it removes it and returns its value.

Example: Print value of the removed item

L = ['red', 'green', 'blue']
x = L.pop(1)
print(x)    # green

When you don’t specify the index on pop(), it assumes the parameter to be -1 and removes the last item.

Example: Remove last item

L = ['red', 'green', 'blue']
L.pop()
print(L)	# ['red', 'green']