Python 3 reference · Set Methods
Python Set clear() Method
Remove every element from the set in place, leaving an empty set. Other references to the set see the change.
Python 3 Since 3.0
Syntax
set.clear()
Return value
None.
Examples
s = {1, 2, 3}
s.clear()
print(s)
Output
set()
s = {1}
alias = s
s.clear()
print(alias)
Output
set()
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
set.discard()· Remove an element if it is present; do nothing if it isn't. The no-error version of remove().set.pop()· Remove and return an arbitrary element of the set. Raises KeyError if the set is empty.- Python Sets · tutorial