当我尝试使用 python 的 not
运算符检查列表是否为空时,它的行为很奇怪。
我尝试对列表使用 not
运算符来检查它是否为空。
>>> a = []
>>> not (a)
True
>>> not (a) == True
True
>>> not (a) == False
True
>>> True == False
False
not (a) == False
的预期输出应该是 False。
最佳答案
==
有 higher precedence比不是
。 not (a) == False
被解析为 not (a == False)
。
关于python - `not` 运算符与 python 列表的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58017682/