a=543
b=543
print(id(a),id(b))
print(a is b)
I am a Python newbie and my understanding of the above code is that
a = 543
=> Since 543 is not in the small integer cache range of -5 to 256, a new pyobject of type integer with value 543 is created and the name/labela
is given to that pyobjectb = 543
=> a new pyobject of type integer with value 543 is AGAIN created and the name/labelb
is given to that pyobject- Since
a
andb
refer to two different objects, their identities are different and thusid(a)==id(b)
must returnFalse
Below is the snapshot of running the above code using Python interpreter in terminal. And the result is what I expected
But the same code when ran through VS Code is returning same id for both a
and b
and id(a)==id(b)
as True
Is my understanding that a different object is created every time incorrect?
- If yes, why is it behaving that way with Python interpreter?
Or is just VSCode doing something that I don't understand yet?