1 == 0 in (0,1) - False; What for?

How does Python parse the first of the following three expressions? (I expected it to be the same as the second, since == and in have the same priority.)

 >>> 1 == 0 in (0,1), (1==0) in (0,1), 1 == (0 in (0,1)) (False, True, True) 
+5
source share
1 answer

See the documentation of comparison operators : they are constrained, not grouped. So, 1 == 0 in (0,1) equivalent to (1==0) and (0 in (0,1)) , which is obviously not true.

+5
source

All Articles