if listA== [ ] more simplified version

This question already has an answer here:

  • How do I check if a list is empty? 25 answers

  • Empty lists evaluate as falsy, so you can also do this, which is what PyCharm may be talking about:

    if not listA:
        return "yes!"
    

    There are some side effects since the above code will return "yes!" whenever list is False , an empty string ( "" ), None , an empty dict ( {} ), an empty set ( set() ) and basically anything else that python treats as falsy

    链接地址: http://www.djcxy.com/p/22496.html

    上一篇: 你如何检查列表是否空白?

    下一篇: 如果listA == []更简化版本