|
|
|
|
|
by jreese
1476 days ago
|
|
This is only true for string literals. Strings constructed at runtime may (and often will) end up as separate objects: >>> a = "this is a long sentence in a string literal"
>>> b = "this is a long" + " sentence in a " + "string literal"
>>> a is b
False
>>> id(a)
4386376272
>>> id(b)
4387721264
>>> a == b
True
|
|
If you test at the shell it apparently misses it (though it works for smaller strings e.g. "abc" / "a" + "b" + "c"), but if you put the same thing in a file and run it, it'll tell you the two strings are identical.