python - how to tell if a dictionary is empty? How to tell if a list is empty? How to tell if a tuple is empty?

When dealing with dictionary{}, list[], and tuple (), sometimes it is necessary to judge the dictionary, list, and tuple, and then process the data if it is not empty.
In python, empty {}, [], () are all equivalent to False. So it is easy to judge, see the code:

lists = [ ] 
if lists : 
    print ( 'This list is not empty' )

if  not lists : 
    print ( 'This list is empty' )

# Other dictionaries and tuples, the judgment method is the same as above
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

Related: python - how to tell if a dictionary is empty? How to tell if a list is empty? How to tell if a tuple is empty?