如何检查Python中的列表是否为空?

这个问题在这里已经有了答案:

  • 如何检查列表是否为空? 25个答案

  • if not myList:
      print "Nothing here"
    

    在布尔上下文if some_list:列表的计算结果为False(比如if some_list:


    我喜欢Zarembisty的回答。 尽管如果你想更加明确,你总是可以这样做:

    if len(my_list) == 0:
        print "my_list is empty"
    
    链接地址: http://www.djcxy.com/p/22489.html

    上一篇: How to check if a list is empty in Python?

    下一篇: Magento Error when Disable module