Python Practice › Set Programs › Program 34
Is a set empty?
Write a Python program to check whether a set is empty.
Input
set(), {1}Output
set() empty
{1} not emptyApproach
- Empty sets are falsy.
Solution
for s in [set(), {1}]: print(s, "empty" if not s else "not empty")Output
set() empty
{1} not emptyLearn the concept
New to this topic? Read the lesson, then come back.