Method Name:
pop
Method Signature:
pop()
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.
Example:
import collections
seriesDeque = collections.deque((10,30,50,70,90)) print("Deque of numbers:") print(seriesDeque)
removedElem = seriesDeque.pop()
print("pop removed the number:%d"%(removedElem))
print("Deque elements after a pop:") print(seriesDeque) |
Output:
Deque of numbers: deque([10, 30, 50, 70, 90]) pop removed the number:90 Deque elements after a pop: deque([10, 30, 50, 70]) |