[Tutor] When are strings interned?
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
> >>> n is o
> >>> p = "green ideas"
> >>> q = "green ideas"
> >>> p == q
> >>> p is q
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor