How python object memory works for int less than -5 and greater 256

时间:2018-04-20 21:20:24

标签: python

In my understanding, all things in python are object and some of them per-allocate memory to them (for int the range is from -5 to 256).
My question is if the address not per-allocate, does it create in fly?

for example:

print id(256)
a = 256
print id(a)

36609008
36609008

this example indicates variable a is referring the object 256's memory, thus they have same address.

print id(300)
a = 300
print id(a)

106711544
106708304

for the example above:

  1. does python create two objects? (it seems yes)
  2. why -5 to 256?
  3. would those per-allocated object be reused to create new objects?

0 个答案:

没有答案