According to the Documentation:
The current implementation keeps an array of integer objects for all integers between
-5
and256
, when you create an int in that range you actually just get back a reference to the existing object. So it should be possible to change the value of1
. I suspect the behaviour of Python in this case is undefined. :-)
So the following behaviors are normal.
>>> a = 256
>>> b = 256
>>> a is b
True
>>> c = 257
>>> d = 257
>>> c is d
False
But when i declare two variables like these, i am getting True-
>>> e = 258; f=258;
>>> e is f
True
I have checked the identity of the objects referenced by e and f-
>>> id(e)
43054020
>>> id(f)
43054020
They are same.
My question is what is happening when we are declaring e and f by separating with semicolons? Why are they referencing to the same object (though the values are out of the range of Python's array of integer objects) ?
It would be better, if you please explain it like you are explaining it to a beginner.