I came across a very confusing problem on a website for speed learning Python. It's about the operand != and how it works. The result/outcome of using != between 3 operands baffles me and my classmates. We have tried to search around and couldn't find any discussion/explanation on this. Please help. Specifically, please see below:
True != False != 1
output: True
True != False != True
output: True
True is not False is not True
output: True
Breaking down the first statement step by step, True!=False should be evaluated first to yield a True. This True is then compared against 1 using != again. True != 1 should yield a False. Therefore the entire statement should evaluate to False! But instead a True is produced.
Breaking down the second statement step by step, True!=False should yield True, then this True != True should yield a False. The statement should evaluate to False !But instead a True is produced.
Likewise for the third statement.
Trying the exact same statements in Javascript and JAVA both gave the expected result - False, which makes complete sense. Python however, is the exception.
Note: We know that explicitly forcing the order of the operation by putting parentheses around two of operands gives the "right" result (which is False).We just can't understand why it's the way it is without parentheses.
Any help would be much appreciated.