simultaneous assignment

Steve R. Hastings steve at hastings.org
Tue May 2 23:29:48 EDT 2006


On Tue, 02 May 2006 12:58:14 -0700, Roger Miller wrote:

> Steve R. Hastings wrote:
> 
>> a = 0
>> b = 0
>> a is b  # always true
> 
> Is this guaranteed by the Python specification, or is it an artifact of
> the current implementation?

I believe it's an artifact of the current implementation.  And I only
tested that on CPython; I don't know if it will work like that on
Jython, IronPython, etc.  I can't imagine why the Python spec would
guarantee such a thing anyway.  :-)


> My understanding has been that an
> implementation is free to share integer objects or not, so using 'is'
> as an equality test takes you into undefined territory, regardless  of
> the size of the value.

This sounds correct to me.  (Note: I do not claim to be an authority on
Python!  But there are several authorities here who will no doubt correct
this if I am wrong.)
-- 
Steve R. Hastings    "Vita est"
steve at hastings.org    http://www.blarg.net/~steveha




More information about the Python-list mailing list