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