Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is "False == False != True" True in Python but false in JavaScript? [duplicate]

My trainee just reached out to me and asked why False == False != True evaluates to True in Python, but false in JavaScript.

I think that statement is false / False, no matter how you solve it, it spits out False in my head.

Heres the breakdown:

given: 
False == False != True

#Case 1:
False == False => True
True != True => False

#Case 2:
False != True => True
False == True => False

Am I missing something obvious? I tried JS with != and === but since the type is the same, it keeps the same ouput.

like image 643
SLNM Avatar asked Apr 19 '26 14:04

SLNM


1 Answers

In Python, you have chained comparisons This is usually intuitive for cases like a < b < c, but in that case, it gives that pretty unintuitive result. You need to parse

False == False != True

as

(False == False) and (False != True)

which then evaluates to True

like image 67
Florent Monin Avatar answered Apr 21 '26 04:04

Florent Monin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!