To check if a Set is empty in Python, you can use the len function or check if the Set is evaluated as False.
In this example,
# Define set
my_set = {'apple', 'banana', 'orange'}
# Check if set is empty using len function
if len(my_set) == 0:
print('Set is empty')
else:
print('Set is not empty')
Set is not empty
In this example,
# Define set
my_set = {'apple', 'banana', 'orange'}
# Check if set is empty using Boolean evaluation
if not my_set:
print('Set is empty')
else:
print('Set is not empty')
Set is not empty
In this tutorial, we learned How to check if a Set is Empty in Python language with well detailed examples.