
List Clear Method –
The list clear method removes all the items from a list.
Syntax of Clear –
list.clear()
How clear works –
In [1]: numbers = [1, 2, 3, 4, 5]
In [2]: # remove all items from the list
In [3]: numbers.clear()
In [4]: numbers
Out[4]: []
Remove all items using del –
You can also remove all items from a list using the del keyword.
In [5]: numbers = [1, 2, 3, 4, 5]
In [6]: del numbers[:]
In [7]: numbers
Out[7]: []