在Python中,
1 in {1} == True
Run Code Online (Sandbox Code Playgroud)
也就是False为什么?
我首先认为这是由于运算符优先级造成的,但我能找到的所有内容(见下文)告诉我表达式是从左到右计算的:
1 in {1}是TrueTrue == True是True此外,任何其他优先级都会导致TypeError:
{1} == True是False1 in False返回一个TypeErrorPython 从左到右计算表达式。
https://docs.python.org/3/reference/expressions.html#evaluation-order
还,
https://docs.python.org/3/reference/expressions.html#operator-precedence