all Python 3Dictionaries (dict)function
dict.clear
removal
Remove all items, leaving an empty dict (in place).
Syntax
d.clear()
clear() empties the object itself, so every reference to that dict sees the change; d = {} merely rebinds the name and leaves the old dict intact for anyone else holding it. That difference is why clear() is the right call for shared caches and for a dict passed into a function whose caller must see the result.
Examples
d = {'a': 1, 'b': 2}
d.clear()
print(d) # → {}
print(len(d)) # → 0
See also
Open in the full glossarydocs.python.orgReport an inaccuracy