CKTIS / Python
set.clear
Removes every element from the same mutable set.
Version: Python 3.14; repository image, production runtime not attested
Syntax
s.clear()Removes every element from the same mutable set.
Existing aliases observe the empty set; allocating a fresh empty set would leave those aliases untouched.
Both s and alias refer to the same mutable set. Clearing it leaves that object with length zero and returns None. Assigning a fresh set to s would preserve the original two members through alias.
s = {1, 2}
a = s
assert s.clear() is None and a is s and not a
Examples
s = {2, 3}
alias = s
s.clear()
print(len(alias))
Result
0
Both s and alias refer to the same mutable set. Clearing it leaves that object with length zero and returns None. Assigning a fresh set to s would preserve the original two members through alias.