[Baypiggies] Trip-up

Shannon -jj Behrens jjinux at gmail.com
Fri Jul 28 22:09:05 CEST 2006


On 7/28/06, Paul McNett <p at ulmcnett.com> wrote:
> I keep reaching the point where I feel like I understand Python and
> could even teach it, but then:
>
>  >>> a = 123456
>  >>> b = 123456
>  >>> a is b
> False
>  >>> 123456 is 123456
> True
>
> I think this is really just an implementation detail rearing its head:
>
>  >>> id(123456)
> 135732936
>  >>> id(123456)
> 135732936
>  >>> id(a)
> 135732948
>  >>> id(b)
> 135732960
>
> So Python is reusing the same id for the unbound 123456 value each time.
> Fair enough, but it still startled me at first. I guess my new mantra is
> "never work with unbound objects..."

"Learning Python" has a really great section covering just this topic
(i.e. "is" with respect to ints).  I agree with Dennis--I rarely use
"is" instead of "==".  I think "is None" and "is not None" are useful,
but I almost always use "==" for everything else.

Best Regards,
-jj


More information about the Baypiggies mailing list