>       Hmmm! Hmmm!
>       Lookee here:
>       ## console session
>      >>> a=[1,2]
>      >>> b=[1,2]
>      >>> a is b
>     False
>      >>> c='1'  ## one byte
>      >>> d='1'  ## one byte
>      >>> c is d
>     True
>      >>> c='1,2'
>      >>> d='1,2'
>      >>> c is d
>     False
> 
>     The Hmmm! is emmitted because I'm thinking that if everything is an
>     object in python, then why does `c is d` evaluate to True when
>     the assigned value is 1 byte and evaluate to False when the assigned
>     value is more that 1 byte?

One and two byte strings are currently optimized in cPython as the same 
object, referenced multiple times.

Note that this is not to be relied upon! Jython, Ironpython, Python3000 
or cPython itself may break it!

Still cannot find a reference doc for this....

Hugo

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to