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: 1 is 1 is allways true while 1.0 is 1.0 may sometimes be true
Type: Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: gregory.p.smith, nassrat, tim.peters
Priority: normal Keywords:

Created on 2008-12-12 01:46 by nassrat, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg77654 - (view) Author: Hatem (nassrat) Date: 2008-12-12 01:46
In [29]: a,b = 1.0,1.0
In [30]: a is b
Out[30]: True
In [31]: a = 1.0
In [32]: b = 1.0
In [33]: a is b
Out[33]: False

# ?!?
msg77655 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2008-12-12 01:50
this is not a bug.  ask this type of question on comp.lang.python.

in short: 'is' is not an equality comparison operator.  it compares
object instance identity.
msg77656 - (view) Author: Hatem (nassrat) Date: 2008-12-12 01:54
Really, "is" is not equality but is object equivalence, wow I did not
know that. So why is the first one true MR. This is truly a bug, why
is the first one optimized while the second one isn't. And how come
integers are allways optimized in that sense. Go close other tickets.
msg77657 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2008-12-12 01:54
"is" is for testing object identity, not numeric equality.  That "1 is
1" is always true is simply an implementation detail common to all
recent versions of CPython, due to CPython caching "very small" integer
objects.  The language definition neither requires nor forbids this, so
any program relying on it is in error.  Likewise any program relying on
"1.0 is 1.0" being false is also in error.
msg77658 - (view) Author: Hatem (nassrat) Date: 2008-12-12 01:58
Atleast you didnt really challenge my inelegence like greg did. If you
look at my small interpreted session, is returned true the first time.
Why is that. The ticket title may not have been perfect, I was trying
to be sarcastic/funny.

I am asking why are objects sometime the same instance while sometimes
aren't for floats.
msg77660 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2008-12-12 02:02
the only intelligence i'm challenging is that this is not appropriate
for a bug tracker.  bring it up on a users mailing list.
msg77661 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2008-12-12 02:39
Please take requests for discussion to comp.lang.python.  Many people
there understand this behavior and will be happy to explain it in as
much detail as you want.  The bug tracker is not the place for this.
History
Date User Action Args
2022-04-11 14:56:42adminsetgithub: 48888
2008-12-12 02:39:31tim.peterssetmessages: + msg77661
2008-12-12 02:02:05gregory.p.smithsetmessages: + msg77660
2008-12-12 01:58:24nassratsetmessages: + msg77658
2008-12-12 01:54:56tim.peterssetnosy: + tim.peters
messages: + msg77657
2008-12-12 01:54:16nassratsetmessages: + msg77656
2008-12-12 01:50:42gregory.p.smithsetstatus: open -> closed
resolution: not a bug
messages: + msg77655
nosy: + gregory.p.smith
2008-12-12 01:46:01nassratcreate