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

Bengt Richter bokr at oz.net
Fri Jun 6 16:43:39 EDT 2003


On Fri, 6 Jun 2003 13:51:15 +0000 (UTC), Joshua Marshall <joshway_without_spam at myway.com> wrote:

>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.
For some meaning of "correct." IWT old-style string exceptions would break.

Regards,
Bengt Richter




More information about the Python-list mailing list