Google News
logo
Python Program to Empty a set
To empty a set in Python, you can use the `clear()` method. Here's an example :
Program :
# create a set
my_set = {1, 2, 3, 4, 5}

# clear the set
my_set.clear()

# print the set
print(my_set)
Output :
set()
Alternatively, you can also create a new empty set by assigning an empty set to the variable :
Program :
# create a set
my_set = {1, 2, 3, 4, 5}

# create a new empty set
my_set = set()

# print the set
print(my_set)
Output :
set()