set.clear() Clear set
Last updated: 2026-09-22
set.clear() Clear set
set.clear() removes all elements.
| Category | Set Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
set.clear()
Returns:None (removes all elements from the set).
Mutates the original:Yes (in place)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
set()
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat does clear() do?
AIt empties all elements of the set in place, turning it into the empty set set().
QWhat is the difference from s = set()?
Aclear() keeps the original set object, so other references see the clearing; s = set() rebinds to a new object, and other references still point to the old set.
QWhat does clear() return?
ANone; it operates in place.