Pop() Method Of Deque Class

Method Name:



Method Signature:



Method Overview:

  • pop() removes an element from the right side of the deque and returns the value.


  • pop() operation is an essential method on a stack which removes the element that came in last.


  • pop() implements the LIFO on a stack. Since a deque() is both a stack and queue, pop() method is provided as part of the deque implementation.


  • Invoking pop() on a empty deque object will raise an exception of type IndexError.



import collections


seriesDeque = collections.deque((10,30,50,70,90))

print("Deque of numbers:")



removedElem = seriesDeque.pop()


print("pop removed the number:%d"%(removedElem))


print("Deque elements after a pop:")




Deque of numbers:

deque([10, 30, 50, 70, 90])

pop removed the number:90

Deque elements after a pop:

deque([10, 30, 50, 70])

Copyright 2023 © pythontic.com