gpt4 book ai didi

python - `not` 运算符与 python 列表的奇怪行为

转载 作者:太空狗 更新时间:2023-10-30 00:28:55 26 4
gpt4 key购买 nike

当我尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com