[Tutor] When are strings interned?

Andrew Fithian afith13 at gmail.com
Thu Jul 2 03:56:38 CEST 2009


My guess is that Python sees the space and decides it isn't a short
string so it doesn't get interned. I got the expected results when I
used 'green_ideas' instead of 'green ideas'.
-Drew



On Wed, Jul 1, 2009 at 6:43 PM, Marc Tompkins<marc.tompkins at gmail.com> wrote:
> On Wed, Jul 1, 2009 at 5:29 PM, Robert Berman <bermanrl at cfl.rr.com> wrote:
>>
>> > >>> n = "colourless"
>> > >>> o = "colourless"
>> > >>> n == o
>> > True
>> > >>> n is o
>> > True
>> > >>> p = "green ideas"
>> > >>> q = "green ideas"
>> > >>> p == q
>> > True
>> > >>> p is q
>> > False
>> >
>> > Why the difference?
>>
>> The string p is equal to the string q. The object p is not the object q.
>>
>> Robert
>
> Yes, but did you read his first example?  That one has me scratching my
> head.
> --
> www.fsrtechnologies.com
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


More information about the Tutor mailing list