dict.clear() Clear dict
Last updated: 2026-09-22
dict.clear() Clear dict
dict.clear() removes all items.
| Category | Dict Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
dict.clear()
Returns:None (removes all items from the dict).
Mutates the original:Yes (in place)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
{}
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat is the difference between clear() and d = {}?
Aclear() empties in place, so other variables referencing the same dict also see the clearing; d = {} rebinds to a new object, and other references still point to the old dict.
QWhat does clear() return?
ANone.
QCan the dict still be used after clearing?
AYes; d becomes an empty dict {} and you can keep adding key-value pairs to it.