Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does `False is False is False` evaluate to `True`?

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 
like image 336
pbaranski Avatar asked Jan 23 '15 06:01

pbaranski


People also ask

What does true and false evaluate to?

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.

Is false == false true?

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.

Why is true and false false in Python?

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.


1 Answers

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.

like image 75
zehnpaard Avatar answered Oct 13 '22 07:10

zehnpaard