a = 1234
b = 1234
print(id(a), id(b))
In the above script both IDs are the same. a
and b
refer to the same object. When running the commands one by one in a Python console the IDs are different:
>>> a = 1234
>>> b = 1234
>>> print(id(a), id(b))
2445680 6579168
but:
>>> print(id(1234), id(1234))
6579472 6579472
Why is 1234
a different object in successive commands, but not in one command or in a script?
I tested this on CPython 3.5.2.