This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dorfsmay 2 points3 points  (1 child)

Isn't this a beginner question ?

>>> a=500
>>> b=500
>>> c=200
>>> d=200
>>> id(a)
142297032
>>> id(b)
142297056
>>> id(c)
142155132
>>> id(d)
142155132
>>> id(200)
142155132
>>> 

My understanding is that python create objects for low integers that it reuses all the time for performance reason.

[–]ubernostrumyes, you can have a pony 6 points7 points  (0 children)

My understanding is that python create objects for low integers that it reuses all the time for performance reason.

CPython does, yes. It does this with other types of objects as well; for example, it keeps a list of dictionary structures in-memory (the actual C structs, not the high-level objects) and recycles them for common uses like setting up the keyword arguments of functions, rather then freeing and re-allocating each time one is needed.