Python: Checking if a 'Dictionary' is empty doesn't seem to work

前端 未结 8 576
旧巷少年郎
旧巷少年郎 2020-12-02 04:27

I am trying to check if a dictionary is empty but it doesn\'t behave properly. It just skips it and displays ONLINE without anything except of display the m

8条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-02 04:57

    use 'any'

    dict = {}
    
    if any(dict) :
    
         # true
         # dictionary is not empty 
    
    else :
    
         # false 
         # dictionary is empty
    

提交回复
热议问题