Why in Python it is evaluated this way:
>>> False is False is False True
but when tried with parenthesis is behaving as expected:
>>> (False is False) is False False
TRUE (say: not true) to evaluate to FALSE and ! FALSE (say: not false) to evaluate to TRUE. Try using the NOT operator and the equals operator to find the opposite of whether 5 is equal to 7.
In Math a = b = c mean all a = b , b = c and a = c . So True is False == False means True == False and False == False and True == False , which is False . For boolean constants, is is equivalent to == . Actually, a is b == c only means (a is b) and (b == c) : a and c are not compared.
In Python, the two Boolean values are True and False (the capitalization must be exactly as shown), and the Python type is bool. In the first statement, the two operands evaluate to equal values, so the expression evaluates to True; in the second statement, 5 is not equal to 6, so we get False.
Chaining operators like a is b is c
is equivalent to a is b and b is c
.
So the first example is False is False and False is False
, which evaluates to True and True
which evaluates to True
Having parenthesis leads to the result of one evaluation being compared with the next variable (as you say you expect), so (a is b) is c
compares the result of a is b
with c
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With