Python .popleft()

Anonymous contributor's avatar
Anonymous contributor
Published Oct 23, 2025
Contribute to Docs

The deque.popleft() method removes and returns the element from the left end (first element) of a deque object. A deque (double-ended queue) allows elements to be added or removed efficiently from both ends. Calling .popleft() on an empty deque raises an IndexError.

  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours

Syntax

deque.popleft()

Parameters:

The .popleft() method does not take any parameters.

Return value:

Returns the element removed from the left end of the deque.

Example

In this example, the first element is removed from the left end of a deque:

from collections import deque
# Create a deque with several elements
queue = deque(['apple', 'banana', 'cherry'])
# Remove the leftmost element
left_item = queue.popleft()
print("Removed element:", left_item)
print("Deque after popleft():", queue)

The output of this code is:

Removed element: apple
Deque after popleft(): deque(['banana', 'cherry'])

Codebyte Example

In this example, a deque is used to simulate a queue of customers. The first customer is served using .popleft():

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy

  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours