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

Empty a setTry it yourself
s = {1, 2, 3}
s.clear()
print(s)

Output

set()
References see the changeTry it yourself
s = {1}
alias = s
s.clear()
print(alias)

Output

set()

Version history

VersionChange
Python 3.0Added