You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes. The expression evaluates false because not of an integer is always false unless the integer is zero. And then if you are trying to compare a boolean false (evaluated from the not expression) with an integer that will also always be false.
not is less binding than == so I believe that not a == b is (in most cases?) the same as a != b. Since == and is have the same precedence, this is easier to see this way:
>>> not 1
False
>>> not 1 is True
True
If not bound more tightly, then it would be the same as (not 1) is True which doesn't match the behavior. But instead we get not (1 is True).
Activity
OrangeTux commentedon Jul 23, 2020
What do you mean? Instead of
you suggest:
dmhouston95 commentedon Jul 23, 2020
Yes. The expression evaluates false because not of an integer is always false unless the integer is zero. And then if you are trying to compare a boolean false (evaluated from the not expression) with an integer that will also always be false.
dmhouston95 commentedon Jul 23, 2020
This would also be vaild
rgov commentedon Jul 24, 2020
See operator precedence: https://docs.python.org/3/reference/expressions.html#operator-precedence
notis less binding than==so I believe thatnot a == bis (in most cases?) the same asa != b. Since==andishave the same precedence, this is easier to see this way:If
notbound more tightly, then it would be the same as(not 1) is Truewhich doesn't match the behavior. But instead we getnot (1 is True).However
!=reads better to me.