On Wed, Jul 1, 2009 at 4:44 PM, Angus Rodgers <ang...@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.
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor