[Tutor] When are strings interned?
Robert Berman
bermanrl at cfl.rr.com
Thu Jul 2 02:29:35 CEST 2009
On Wed, 2009-07-01 at 16:44 +0100, Angus Rodgers wrote:
> Hello, world!
>
> This is my first post to the Tutor list (although I've already
> posted to comp.lang.python a couple of times).
>
> I'm currently reading Chapter 4 of Wesley Chun's book, "Core
> Python Programming" (2nd ed.).
>
> I find this, in Python 2.5.4, on my Win98SE system (using IDLE):
>
> >>> 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
More information about the Tutor
mailing list