I notice that, for integer and string:
a=1 ; b=1
c='abc' ; d='abc'
print(id(a), id(b))
print(id(c), id(d))
In this circumstance, a would share same memory address with b, c would share same memory address with d
On the other hand, for list, set ...etc.:
e=[1,2,3] ; f=[1,2,3]
g=(1,2,3) ; h=(1,2,3)
i={1,2,3} ; j={1,2,3}
k={"a":1,"b":2} ; l={"a":1,"b":2}
print(id(e), id(f))
print(id(g), id(h))
print(id(i), id(j))
print(id(k), id(l))
In this circumstance, e won't share same memory address with f, g won't share same memory address with h ... etc.
So I want to ask:
- Is there any principle of how python allocated memory for different datatype?
- Does python official document explain about this ? (I can't find any)
Thank you
idvalues.