collections.deque · Python

popleft

Removes and returns the leftmost element: the dequeue operation of a FIFO queue.

deque.popleft()

Complexity

Best caseO(1)
Worst caseO(1)
Extra spaceO(1)

Advance the left index; free the block when it empties.

Tested example

queue = deque([1, 2, 3])
assert queue.popleft() == 1  # FIFO: first in, first out
assert queue.popleft() == 2
queue.popleft()
try:
    queue.popleft()
    raise AssertionError("expected IndexError")
except IndexError:
    pass
Runs in the test suite on CPython 3.14.0 · examples/python/tests/test_collections_deque.py

Behaviour

Returns
The leftmost element.
Errors and preconditions
IndexError if the deque is empty.
Changes
Length shrinks by 1.
Memory and invalidation
May free a block.