expression can be simplified on boolean literal

This question already has an answer here:

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

  • are None and [] empty list the same thing?

    Nope, and it will result in erroneous behavior:

    seq_group = []
    
    if seq_group is None:
        print("it is empty")
    

    This doesn't print anything, None is completely different to [] , value and identity wise. None indicates the absence of a value, [] indicates a list with no values. The confusion might arise from the fact that both happen to evaluate False in conditionals.

    The warning is probably due to the fact that you can simply use seq_group with not instead of using a literal with == :

    if not seq_group:
        print("it is empty")
    
    链接地址: http://www.djcxy.com/p/22494.html

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

    下一篇: 表达式可以在布尔文字上简化