Python List clear()
The clear()
method removes all elements from a list, effectively making it an empty list.
Syntax
list.clear()
Parameters
The clear()
method doesn’t take any parameters
Return
It doesn’t return any value (implicitly returns None
). It empties the list.
Example: Remove all items from a list
my_list = [5, 10, 15, 20]
my_list.clear()
print(my_list) # Output: []