"/a" is not "/a" ?

Emanuele D'Arrigo manu3d at gmail.com
Fri Mar 6 22:31:02 CET 2009


Thank you everybody for the contributions and sorry if I reawoke the
recurring "is vs ==" issue.  I -think- I understand how Python's
object model works, but clearly I'm still missing something. Let me
reiterate my original example without the distracting aspect of the
"==" comparisons and the four variables:

>>> 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?

Manu



More information about the Python-list mailing list