expression can be simplified on boolean literal
本问题已经有最佳答案,请猛点这里访问。
我有以下代码复制了
Expression can be simplified
This expression detects equality comparison with a boolean literal.
1 2 3 | seq_group = [] if seq_group == []: # warning here print("it is empty.") |
如果我把代码改为,
1 | if seq_group is None: |
是否会修正警告,但真正的问题是,
干杯
are
None and[] empty list the same thing?
不,它会导致错误的行为:
1 2 3 4 | seq_group = [] if seq_group is None: print("it is empty") |
这不打印任何内容,
警告可能是因为您可以简单地将
1 2 | if not seq_group: print("it is empty") |