id() trickery
Jeff Pinyan
jeffp at crusoe.net
Sat Mar 18 14:51:37 EST 2000
Well, I've broken my brain again. Could someone explain this to me?
>>> a = id(1)
>>> a, id(1)
(732968, 732968)
>>> b = id(1)
>>> b, id(1)
(732968, 732968)
>>> a,b,id(a),id(b)
(732968, 732968, 732236, 732212)
>>> a = b + 0
>>> a,b,id(a),id(b)
(732968, 732968, 732188, 732212)
>>> a = b
>>> a,b,id(a),id(b)
(732968, 732968, 732212, 732212)
>>> a = b + 0
>>> a,b,id(a),id(b)
(732968, 732968, 732188, 732212)
Could someone tell me why the value returned by id(), which is just an
int, says type(), is acting a little fruity for me? If a and b hold the
same integer, shouldn't they have the same value for id()? And why do
>>> a = b # and
>>> a = b + 0
have two different effects?
--
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve japhy at pobox.com
http://www.pobox.com/~japhy/ http://pinyaj.stu.rpi.edu/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
More information about the Python-list
mailing list