In my attempt to learn Python I have been writing code from tutorials and my own. I am using Python 3.
The piece of code that is doing me in:
>>>print(not 1 == 1 or 6 == 6 and 9 == 9)
True
I've run the separate parts of this code. It seems the OR operator is negating itself with a double True. (not True or True) outputs True instead of False? Isn't the or operator suppose to conclude upon the first True and the not operator returns True as False?
You should look in to operator precedence.
Let's examine this expression and handle each operator according to their precedence:
First, the
==
operators are executed, so we get:Then, the
not
operator:Then, the
and
operator:Then, the
or
operator, producing the result you're seeing: