Python .pop()

Anonymous contributor's avatar
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.

  • 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

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 deque
dq = deque([10, 20, 30, 40])
# Remove and return the rightmost element
item = dq.pop()
print("Removed element:", item)
print("Deque after pop:", dq)

This example results in the following output

Removed element: 40
Deque 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():

Code
Output
Loading...

All contributors

Contribute to 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