[Tutor] When are strings interned?
Jeremiah Dodds
jeremiah.dodds at gmail.com
Thu Jul 2 10:49:09 CEST 2009
On Wed, Jul 1, 2009 at 4:44 PM, Angus Rodgers <angusr at bigfoot.com> 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?
> --
>
>
IIRC, in cPython (the "defaul" python available from python.org), there is
an optimization done for strings (and I think integers) below a certain
size. This is an implementation detail, and could be different in (for
instance) Jython.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090702/e7f908c2/attachment.htm>
More information about the Tutor
mailing list