Terry Reedy wrote:
Joe Strout wrote:
That's not necessarily true. If you have
a = "par" + "rot"
b = "parrot"
then, most likely (though it depends on how clever the compiler
optimizations are), there are two different string objects containing
the data "parrot".
>>> a='par'+'rot'
>>> b='parrot'
>>> a is b
True
One exactly doesn't really say much. It's implementation dependent, and
depends on the length of the string:
>>> a = 'this is a much longer ' + 'parrot'
>>> b = 'this is a much longer parrot'
>>> a is b
False
In practice, tests like these are pretty much never useful. It's
completely implementation dependent when and under what circumstances
fundamental immutable objects are reused, and it's not useful anyway;
what you care about is whether two objects are equal or not, not whether
they're the same object through some optimization behind the scenes.
--
Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
All delays are dangerous in war.
-- John Dryden, 1631-1700
--
http://mail.python.org/mailman/listinfo/python-list