How to check if dictionary is empty in Python

2 Answers

0 votes
dict = {}

if not dict:
    print('Empty')
else:
    print('Not empty')
 
 
 
'''
run:
 
Empty
 
'''

 



answered Jan 12, 2021 by avibootz
0 votes
dict = {}

if (len(dict) == 0):
    print('Empty')
else:
    print('Not empty')
 
 
 
'''
run:
 
Empty
 
'''

 



answered Jan 12, 2021 by avibootz

Related questions

1 answer 161 views
1 answer 165 views
4 answers 305 views
305 views asked Apr 24, 2021 by avibootz
2 answers 276 views
2 answers 190 views
1 answer 188 views
...