Clear() method of deque class in Python

Method Name:

clear

 

Method Signature:

clear

 

Method Overview:

  • clear() method of deque class in python removes all the elements of a deque object.

 

Example:

import collections

 

evenNumbers = (2,4,6,8)

evenDeque   = collections.deque(evenNumbers)

 

print("Deque object with even numbers less than 10:")

print(evenDeque)

print("Deque length:%d"%(len(evenDeque)))

 

evenDeque.clear()

 

print("Deque object after calling clear() method:")

print(evenDeque)

print("Deque length:%d"%(len(evenDeque)))

 

Output:

Deque object with even numbers less than 10:

deque([2, 4, 6, 8])

Deque length:4

Deque object after calling clear() method:

deque([])

Deque length:0


Copyright 2024 © pythontic.com