Python Forum
Does the integer implementation matter? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: Does the integer implementation matter? (/thread-21940.html)



Does the integer implementation matter? - ichabod801 - Oct-21-2019

Some integers are stored in a table, so two variables assigned to integers might have the same address, or they might have different addresses. This comes up periodically on these forums, most recently here.

I don't care why this happens.

My question is: does it matter? I think I have been programming Python for 17 years now, and never have the details of the integer implementation mattered to any of my programs. Has it ever mattered to any of your code? Can someone post a code snippet where it did matter?


RE: Does the integer implementation matter? - Gribouillis - Oct-22-2019

I guess it matters if you start worrying about where the python objects are really stored in memory. For example if you're computing the actual size of python objects
>>> from pympler import asizeof
>>> x = 80000
>>> y = 80000
>>> 
>>> asizeof.asizeof([x, y])
144
>>> asizeof.asizeof([x, x])
112
>>> x = 5
>>> y = 5
>>> asizeof.asizeof([x, y])
112



RE: Does the integer implementation matter? - snippsat - Oct-22-2019

Don't think it matter so much at all,but when people discover that stuff eg integer in Python can point to same place.
Then get Thread where explain this with id() and other stuff.
[Image: python-gc-4-638.jpg?cb=1400908049]
After knowing this probably never need to worry about this again in regular Python programming.
One of the strength of Python is that memory management Doh is done automatically,so we don't need to mess with it Cool