Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,695 questions

57,003 answers

573 users

How to check if set is empty in Python

4 Answers

0 votes
def is_set_empty(st):
    return len(st) == 0

st1 = {1, 4, 5, 7, 2, 8}
st2 = set()

print(is_set_empty(st1))
print(is_set_empty(st2))

print(is_set_empty({3, 5, 8}))



  
  
'''
run:
  
False
True
False

'''

 



answered Apr 24, 2021 by avibootz
0 votes
def is_set_empty(st):
    return not bool(st)

st1 = {1, 4, 5, 7, 2, 8}
st2 = set()

print(is_set_empty(st1))
print(is_set_empty(st2))

print(is_set_empty({3, 5, 8}))



  
  
'''
run:
  
False
True
False

'''

 



answered Apr 24, 2021 by avibootz
0 votes
def is_set_empty(st):
    return st == set()

st1 = {1, 4, 5, 7, 2, 8}
st2 = set()

print(is_set_empty(st1))
print(is_set_empty(st2))

print(is_set_empty({3, 5, 8}))



  
  
'''
run:
  
False
True
False

'''

 



answered Apr 24, 2021 by avibootz
0 votes
def is_set_empty(st):
    return not st

st1 = {1, 4, 5, 7, 2, 8}
st2 = set()

print(is_set_empty(st1))
print(is_set_empty(st2))

print(is_set_empty({3, 5, 8}))



  
  
'''
run:
  
False
True
False

'''

 



answered Apr 24, 2021 by avibootz

Related questions

2 answers 296 views
296 views asked Oct 10, 2022 by avibootz
1 answer 215 views
1 answer 203 views
1 answer 212 views
1 answer 219 views
2 answers 316 views
...