Method signature:
popleft()
Parameters:
None
Return value:
Returns the removed element.
Overview:
- A deque Python is double ended queue. Elements can be added and removed from either side of the deque.
- The popleft() method removes an element from the left side of the deque and returns the element.
- Invoking popleft() on an empty deque raises an exception of type IndexError.
Example:
|
# Example Python program that removes an element # Create a deque # Remove an element from the left of the deque print("Deque elements after invoking popleft():") |
Output:
|
Deque elements before invoking popleft(): |