Python .popleft()
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.
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 elementsqueue = deque(['apple', 'banana', 'cherry'])# Remove the leftmost elementleft_item = queue.popleft()print("Removed element:", left_item)print("Deque after popleft():", queue)
The output of this code is:
Removed element: appleDeque 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():
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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