This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Something wrong when Calculate "3==3 is not True"
Type: behavior Stage: resolved
Components: Subinterpreters Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ET, serhiy.storchaka
Priority: normal Keywords:

Created on 2021-09-17 07:45 by ET, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg402010 - (view) Author: Wang Bingchao (ET) Date: 2021-09-17 07:45
I use python3.7 python3.6 python2.7, and run the following code: 
print(3==3 is not True)
print(3==3 is True)
print(3==2 is not True)
print(3==2 is True)
I got the same results as follow: 
True
False
False
False
but I don't think it is a reasonable result, it may be bugs?
msg402012 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-09-17 09:06
No, it is a feature.

Python allows you to chain comparison operations, so you can write 0 < x <= 10 which is equivalent to (0 < x) and (x <= 10).

And "is" is a comparison operation. So `3==3 is not True` is equivalent to `(3==3) and (3 is not True)` which is evaluated to `True and True` which is equal to True.
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89393
2021-09-17 09:06:22serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg402012

resolution: not a bug
stage: resolved
2021-09-17 07:45:12ETcreate