相关疑难解决方法(0)

为什么([1,0] == True中的1)评估为False?

当我看到这个问题的答案时,我发现我不明白自己的答案.

我真的不明白这是如何被解析的.为什么第二个示例返回False?

>>> 1 in [1,0]             # This is expected
True
>>> 1 in [1,0] == True     # This is strange
False
>>> (1 in [1,0]) == True   # This is what I wanted it to be
True
>>> 1 in ([1,0] == True)   # But it's not just a precedence issue!
                           # It did not raise an exception on the second example.

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    1 in ([1,0] == …
Run Code Online (Sandbox Code Playgroud)

python syntax operator-precedence

149
推荐指数
1
解决办法
4630
查看次数

标签 统计

operator-precedence ×1

python ×1

syntax ×1