In Python, you can use the len()
function to check if a Set is not empty.
In this example,
my_set
and initialize it with some elements.len()
function on the Set my_set
to determine its length.my_set = {1, 2, 3} # Or my_set = set() for an empty Set
if len(my_set) > 0:
print('The Set is not empty')
else:
print('The Set is empty')
The Set is not empty
In this example,
empty_set
.len()
function on the Set empty_set
to determine its length.empty_set = set()
if len(empty_set) > 0:
print('The Set is not empty')
else:
print('The Set is empty')
The Set is empty
In this tutorial, we learned How to check if a Set is Not Empty in Python language with well detailed examples.