Steven D'Aprano <[email protected]> added the comment:
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``.
----------
nosy: +steven.daprano
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38001>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com