The set
data type represents a collection of unordered, unique elements. It contains various methods for manipulating and extracting information about a set. Sets are mutable, meaning that operations that actually modify the sets are possible.
The clear()
method is used to remove all elements from a set, effectively making it an empty set.
set.clear()
The method does not take any arguments, it simply removes all the elements from the set and returns None
.
myset = {1, 2, 3, 4}
print(myset)
#remove all elements
myset.clear()
#The set is now empty
print(myset)