[Tutor] Object references and caching/interning

Bjorn Egil Ludvigsen bludvigsen at gmail.com
Tue Dec 15 17:43:54 CET 2009


This is my frist post here. I am learning Python and Qt and am trying to
understand a pecularity with object references. I think I get the integer
part, but for floating point it seems like the caching/interning process
works a little bit here and there:

1) Same object on command line
>>> a, b = 5.0, 5.0
>>> id(a), id(b)
(11140648, 11140648)

2) Different object on command line
>>> a = 5.0
>>> b = 5.0
>>> id(a), id(b)
(11140616, 11140600)

3) Same object in script
When running the last assignments for the float objects in a script (point
2) above, one line per assignment), it is cached again and the variables
refer to the same object. Why is it different on a command line and in a

How can you know when you create a new object or not, are there any rules?

Thanks for a great forum.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091215/31366076/attachment.htm>

More information about the Tutor mailing list