easy question on parsing python: "is not None"

Matt Schinckel matt at schinckel.net
Fri Aug 13 04:52:07 CEST 2010


On Aug 6, 8:15 am, "Rhodri James" <rho... at wildebst.demon.co.uk> wrote:
> On Thu, 05 Aug 2010 17:07:53 +0100, wheres pythonmonks  
>
> <wherespythonmo... at gmail.com> wrote:
> > Well, I am not convinced of the equivalence of not None and true:
[snip]
> >>> "spam, eggs, chips and spam" is "spam, eggs, chips and spam"
> True
> >>> a = "spam, eggs, chips and spam"
> >>> b = "spam, eggs, chips and spam"
> >>> a is b
> False

but:

>>> a = "hello"
>>> b = "hello"
>>> a is b
True

Ooh, that looks dangerous. Are they the same object?

>>> a += "o"
>>> a
'helloo'
>>> b
'hello'

Phew.

(Python does not make two copies of small strings until it needs to).

Matt.



More information about the Python-list mailing list