[Baypiggies] Trip-up
Paul McNett
p at ulmcnett.com
Fri Jul 28 17:36:41 CEST 2006
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..."
--
Paul McNett
http://paulmcnett.com
http://dabodev.com
More information about the Baypiggies
mailing list