Python Practice › Set Programs › Program 34

Is a set empty?

EasySet Programs · 34 of 48

Write a Python program to check whether a set is empty.

Advertisement
Input
set(), {1}
Output
set() empty
{1} not empty

Approach

  1. Empty sets are falsy.

Solution

Python
for s in [set(), {1}]:    print(s, "empty" if not s else "not empty")
Output
set() empty
{1} not empty

Learn the concept

New to this topic? Read the lesson, then come back.

More set programs

← All 48 Set Programs

Leave a Comment