Possible Duplicate:
Python “is” operator behaves unexpectedly with integers
>>>a=123
>>>b=123
>>>a is b
True
>>>id(a)==id(b)
TrueMy question is, why is id(a) the same as id(b)?.Usually small integers reference the same cached object in memory for efficiency purposes.
ints are cached. That is an implementation detail that shouldn't matter since ints are immutable anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With