('a' in 'abc' == True) 计算结果为 False

('a' in 'abc' == True) evaluates to False

这是我在摆弄 python 解释器时得到的

[mohamed@localhost ~]$ python
Python 2.7.5 (default, Apr 10 2015, 08:09:14) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 'a' in 'abc'
True
>>> 'a' in 'abc' == True
False
>>> 'a' in 'abc' == False
False 
>>> ('a' in 'abc') == True
True
>>> ('a' in 'abc') == False
False


>>> ('a' in 'abc' == True) or ('a' in 'abc' == False)
False
>>> (('a' in 'abc') == True) or (('a' in 'abc') == False)
True

我的问题是为什么使用括号会给我预期的、逻辑上更合理的输出?

由于运算符链接,in== 不能很好地结合在一起。

'a' in 'abc' == True

转换为 -

'a' in 'abc' and 'abc' == True

引用自documentation-

Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z , except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false).

类似的事情发生在 in== .