1

I played around with python by writing some nonsense code, and noticed a strange behavior with a line of code I wrote.

>>> True != True != True
False

I can't wrap my head around why this statement evaluates to False. At first glance I thought python would surround one of the True != True with parentheses and then evaluate the whole statement, just like 1 + 1 + 1 is equivalent with (1 + 1) + 1 or 1 + (1 + 1). I tried it in python command line:

>>> (True != True) != True
True
>>> True != (True != True)
True

But it seems python chooses another strategy to evaluate True != True != True, since the statements above both evaluates to True.

So the question is, how does python actually interpret True != True != True?

oscfri
  • 2,558
  • 2
  • 27
  • 24

0 Answers0