Strange behaviour of 'is'
Duncan Booth
duncan.booth at invalid.invalid
Fri Sep 22 03:18:39 EDT 2006
Steve Holden <steve at holdenweb.com> wrote:
> Absolutely correct. It would be more interesting to discuss how the
> output from these statements varied between (say) CPython, Jython and
> Iron Python. At the moment the discussion is indeed about insignificant
> implementation trivia.
CPython seems to collapse identical float values if they are in the same
compilation unit:
>>> x = 2.
>>> y = 2.
>>> x is y
False
>>> x = 2.; y = 2.
>>> x is y
True
>>> y = [2., 2.]
>>> y[0] is y[1]
True
IronPython doesn't collapse them even when they are in expression:
IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> x = 2.
>>> y = 2.
>>> x is y
False
>>> x = 2.; y = 2.
>>> x is y
False
>>> y = [2., 2.]
>>> y[0] is y[1]
False
JPython seems to behave in a similar manner to CPython:
Python command console - JPython 2.1
>>> x = 2.
>>> y = 2.
>>> x is y
0
>>> x = 2.; y = 2.
>>> x is y
1
>>> y = [2., 2.]
>>> y[0] is y[1]
1
>>>
Sorry, I don't have a more recent Jython implementation to hand to complete
the comparison.
More information about the Python-list
mailing list