List clear() method Python

The use of list clear() method of Python is straightforward,it removes all the elements from the list object.

 
>>> ls=[ 23 , 'doom' , 65.767 , (23 ,56) , [23]]
>>> ls.clear()
>>> ls
[]

If you ever want to clear all the elements from the list object call the clear() method.


Point to note

Calling pop() is equivalent to :
 
del ls[:]
 
‘ls’ is the object of the list.

>>> ls=[ 23 , 'doom' , 65.767 , (23 ,56) , [23]]
>>> del ls[:]
>>> ls
[]


Leave a Reply

Your email address will not be published. Required fields are marked *