En Fri, 06 Mar 2009 19:31:02 -0200, Emanuele D'Arrigo <man...@gmail.com>
escribió:
a = "a"
b = "a"
a is b
True
a = "/a" <- same as above, except the forward slashes!
b = "/a" <- same as above, except the forward slashes!
a is b
False
So, it appears that in the first case a and b are names to the same
string object, while in the second case they are to two separate
objects. Why? What's so special about the forward slash that cause the
two "/a" strings to create two separate objects? Is this an
implementation-specific issue?
With all the answers you got, I hope you now understand that you put the
question backwards: it's not "why aren't a and b the very same object in
the second case?" but "why are they the same object in the first case?".
Two separate expressions, involving two separate literals, don't *have* to
evaluate as the same object. Only because strings are immutable the
interpreter *may* choose to re-use the same string. But Python would still
be Python even if all those strings were separate objects (although it
would perform a lot slower!)
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list