Python .pop()
Anonymous contributor
Published Oct 28, 2025
Contribute to Docs
The deque.pop() method removes and returns an element from the right end of a deque. Removing an element from either end of a deque occurs in O(1) time.
Syntax
deque.pop()
Parameters:
This method does not take any parameters.
Return value:
Returns the element that was removed from the right end of the deque.
Exceptions:
IndexError: Raised if the deque is empty when.pop()is called.
Example
In this example, a single element is removed from the right end of the deque using .pop():
from collections import deque# Create a dequedq = deque([10, 20, 30, 40])# Remove and return the rightmost elementitem = dq.pop()print("Removed element:", item)print("Deque after pop:", dq)
This example results in the following output
Removed element: 40Deque after pop: deque([10, 20, 30])
Codebyte Example: Popping the two rightmost elements
In this example, elements are removed from the right end of a deque one by one using .pop():
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
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- 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