The clear method
The clear method removes all elements from the set. After using this method, the set will be empty. We do not pass anything in the method parameter.
Syntax
pythonset.clear()
Example
Let's remove all elements from our set:
pythonst = {'a', 'b', 'c'}
st.clear()
print(st)
Result of code execution:
pythonset()
See also
-
method
remove,
which removes elements from a set
-
method
discard,
which removes elements that are in the set
-
method
pop,
which removes the first element from a set
-
method
add,
which adds elements to a set
-
function
len,
which returns the length of the set
-
method
union,
which unites sets