all Python 3Lists (list)function
list.pop
removal
Remove and return the item at the index (last by default); raises IndexError if empty or out of range.
Syntax
lst.pop(index=-1)
Popping from the end is O(1), but pop(0) — or any early index — is O(n) because every later element shifts left. For a FIFO queue use collections.deque with popleft() instead of a list, otherwise large inputs turn quadratic. Unlike del and remove, pop hands the removed value back, which is what makes the take-and-process pattern convenient.
Examples
lst = [1, 2, 3]
print(lst.pop()) # → 3
print(lst.pop(0)) # → 1
print(lst) # → [2]
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy