String/Number Conversion

John Machin sjmachin at lexicon.net
Sat Sep 6 23:49:51 CEST 2008


On Sep 7, 7:29 am, Wojtek Walczak <gmin... at bzt.bzt> wrote:
> On Sat, 06 Sep 2008 23:04:14 +0200, Andreas Hofmann wrote:
> >                  if mult is 1:
>
>                            ^^
> You're testing for identity, not for equality.
> Change it to "if mult == 1". Is it alright now?
>

Although he definitely should not be using "is" here, that can not be
the problem if he is using CPython. As an optimisation, small integers
are interned i.e. for each small integer, there is only one object.

>>> a = 1
>>> b = 10000
>>> a is 1
True
>>> b is 10000
False
>>> id(a)
10897704
>>> id(1)
10897704
>>> id(b)
11893004
>>> id(10000)
12633044
>>>




More information about the Python-list mailing list