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.

Author steven.daprano
Recipients Digin Antony, steven.daprano, xtreak
Date 2019-09-02.00:38:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1567384703.48.0.593158031129.issue38001@roundup.psfhosted.org>
In-reply-to
Content
Further to Karthikeyan Singaravelan comment, the behaviour you see is absolutely correct. The operator isn't behaving differently, it is reporting precisely the truth.

The ``is`` operator tests for object identity, not equality. Python makes no promises about object identity of literals. If you use an immutable literal in two places:

    a = 1234
    b = 1234

the interpreter is free to use the same object for both a and b, or different objects. The only promise made is that ``a == b``.

The Python interpreter currently caches some small integers for re-use, but that's not a language guarantee, and is subject to change without warning. It has changed in the past, and could change again in the future.

The bottom line is that you shouldn't use ``is`` except to test for object identity, e.g. ``if obj is None``.
History
Date User Action Args
2019-09-02 00:38:23steven.dapranosetrecipients: + steven.daprano, xtreak, Digin Antony
2019-09-02 00:38:23steven.dapranosetmessageid: <1567384703.48.0.593158031129.issue38001@roundup.psfhosted.org>
2019-09-02 00:38:23steven.dapranolinkissue38001 messages
2019-09-02 00:38:23steven.dapranocreate