List Methods
clear()
Remove all items from the list.
list.clear()
list.clear() removes every element from the list, reducing its length to zero.
This mutation affects all references to the list.
Result
Returns
None, the list is emptied in place.
Run it
Try it
Run it and change it
items = ["alpha", "beta", "gamma"]
items.clear()
print("Cleared list:", items) Output
Press Run to see what it prints.Worth knowing
- Slice assignment alternative:
del items[:]oritems[:] = []performs the exact same in-place clearing operation.