id(a) == id(b) and a is not b --> bug?

Joshua Marshall joshway_without_spam at myway.com
Fri Jun 6 15:51:15 CEST 2003


Steve McAllister <nosp at m.needed> wrote:
>> If any kind of computation is performed in the arguments, the property
>> you assume may not hold.

> And exactly why is {
> 'foo' is 'foo' is 'foo' is 'foo'
> } always true?  This is quite surprising compared to {
> [] is []
> } ...
> Why are not new string literals dynamically created?

Strings are immutable, so the interpreter is free to use these strings
in multiple places.  It's an optimization--it would also be correct if
"'foo' is 'foo'" were false.




More information about the Python-list mailing list