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

Bengt Richter bokr at
Fri Jun 6 23:18:23 CEST 2003

On 6 Jun 2003 20:43:39 GMT, bokr at (Bengt Richter) wrote:

>On Fri, 6 Jun 2003 13:51:15 +0000 (UTC), Joshua Marshall <joshway_without_spam at> 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.
I would have thought wrong ;-/ Just tried it. Note to self: test before posting ;-/

Bengt Richter

More information about the Python-list mailing list