First Case:
print((True != 12) in (12,14))
We can say that first we evaluate True != 12
condition which give us True
, and then we are evaluating if True
is in the tuple (12,14)
and that's False
.
Third Case:
print(True != (12 in (12,14)))
We can say that first we evaluate (12 in (12,14))
condition which give us True
because 12
is in the tuple (12,14)
. Then we evaluate if True != True
an that's False
.
Second Case:
print( True != 12 in (12,14))
So here is the tricky one. Without the parentheses we don't have where to start evaluating the conditions. To explain this case, I'm gonna give you the next example: if you try the following code (which is pretty similar to the one that we are trying to figure out the result):
print(1 != 2 != 3) #output True
You are gonna get True
and that's because 1 != 2
and 2 != 3
. So as you may have already noticed, it's an implicit AND
. The above code is equal to:
print(1 != 2 and 2 != 3) #output True
So if we take this logic to our case, we are evaluating this:
print( True != 12 and 12 in (12,14)) # => (True and True) #output True
x < y < z
example I wrongly thought the chaining feature only applied to ordering operators. – Siena