You can analyze each of these cases with a module disto determine exactly what is going on. For example:
In [1]: import dis
In [2]: def test():
...: return 3 > 2 is True
...:
In [3]: dis.dis(test)
2 0 LOAD_CONST 1 (3)
3 LOAD_CONST 2 (2)
6 DUP_TOP
7 ROT_THREE
8 COMPARE_OP 4 (>)
11 JUMP_IF_FALSE_OR_POP 21
14 LOAD_GLOBAL 0 (True)
17 COMPARE_OP 8 (is)
20 RETURN_VALUE
>> 21 ROT_TWO
22 POP_TOP
23 RETURN_VALUE
, :
0: 3
3: 3 2
6: 3 2 2
7: 2 3 2
8: 2 True
11: 2
14: 2 True
17: False (comparison was: "2 is True")
20: (False is returned)
Python, . , - , , .
, :
if 3 > 2:
if 2 is True:
return True
return False
: , - . , :
3 > 2 > 1 == 3 > 2 and 2 > 1
:
x op1 y op2 z == x op1 y and y op2 z
.
Edit2: . : https://docs.python.org/2/reference/expressions.html#not-in
comparison ::= or_expr ( comp_operator or_expr )*
comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "<>" | "!="
| "is" ["not"] | ["not"] "in"
is , >, .
. : True == 1, False == 0, 3 > False 3 > (2 is True). . :
5 < 3 is False > 2 is True == False
(5 < 3) and (3 is False) and (False > 2) and (2 is True) == False