views:

61

answers:

2

>>>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?

+2  A: 

ints are cached. That is an implementation detail that shouldn't matter since ints are immutable anyway.

nosklo
+1  A: 

Usually small integers reference the same cached object in memory for efficiency purposes.

jackbot