simultaneous assignment

Mel Wilson mwilson-to at sympatico.ca
Wed May 3 05:04:51 CEST 2006


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? 

AFAIK it's an artifact.  The performance hit it Python 
stopped sharing small integers could be enormous, 
nonetheless sharing isn't part of the specification
>                                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.
> 
I agree.  "is" is for working with linked-lists or trees, or 
other applications where object identity is really and truly 
what you're interested in.

Some amusing is/== facts, some suggested by recent threads

Python 2.4.2 (#1, Jan 23 2006, 21:24:54)
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more 
information.
 >>> 0 is 0.0
False
 >>> -0.0 is 0.0
False
 >>> 0 == 0.0 == -0.0
True
 >>> 1000000 is (2000000/2)
False



More information about the Python-list mailing list