Possible Duplicate:
Python βisβ operator behaves unexpectedly with integers
>>>a=123
>>>b=123
>>>a is b
True
>>>id(a)==id(b)
True
My question is, why is id(a) the same as id(b)?.Aren't they two different instances of class int?
Possible Duplicate:
Python βisβ operator behaves unexpectedly with integers
>>>a=123
>>>b=123
>>>a is b
True
>>>id(a)==id(b)
True
My question is, why is id(a) the same as id(b)?.Usually small integers reference the same cached object in memory for efficiency purposes.
int
s are cached. That is an implementation detail that shouldn't matter since int
s are immutable anyway.
variables
a and b
both are references to the object 123 whose id is unique.
when u assign same value 123 to two diff variables a and b,
then same object 123 is assigned to both variables a and b but reference count made to that object increases in your case refrecnce count for object 123 is two