list.clear
Remove all items from the list.
Python 3.13
list.clear()Return value
Nothing (None); the list is changed in place.
Examples
Clearing a list
Python 3.13
a = [1, 2, 3]
a.clear()
print(a)[]
The list itself is cleared, not the variable
Python 3.13
a = [1, 2]
b = a
a.clear()
print(b)[]
Details
del a[:] does the same. Unlike the assignment a = [], clear() changes the list itself, so the change is visible through all variables that refer to it.
