See this code:
>>> import ctypes
>>> x=12345
>>> y=x
>>> ctypes.c_long.from_address(id(x)).value
2
>>> a=2
>>> b=a
>>> ctypes.c_long.from_address(id(a)).value
116
>>>
for object x it returned expected output but for "a" it's returning an unexpected result
The "expected value" is refcount of an allocated object.
When you assigned
x, you allocated a newintobject. You took another reference, and were unsurprised to see the refcount increment by 1.When you assigned
a, you took a reference on an existing object. The cPython interpreter pre-created a cache of more than two hundred small integers, and then modules youimported took references to some of them. Your example output is just saying there are more than a hundred references extant, cf What's with the integer cache maintained by the interpreter?.