Python Set clear() Method
The clear() method removes all elements from a set, leaving it empty.
Syntax
set.clear()
Parameters
No parameters.
Return Value
Doesn’t return any value (returns None). It modifies the set in-place.
Example:
fruits = {"apple", "banana", "mango", "orange"}
print(fruits) # Output: {'apple', 'mango', 'banana', 'orange'}
# Clear the set
fruits.clear()
print(fruits) # Output: set()
Python sets are unordered, so the elements may appear in a different order each time you print them.
Also note that an empty set is written as set(). The notation {} indicates an empty dictionary, not an empty set.