I'm using Python 3.7.4 and understand the small integers are numbers [-5,256].
I want to know why the result of #2 in the code below returns True
. Shouldn't it be False
?
#1
b=257
c=257
b=b+1
c=c+1
print(id(b))
print(id(c))
print(b is c)
#2
b1=257
c1=257
print(id(b1))
print(id(c1))
print(b1 is c1)
Result in Visual Code Terminal
4306256464
4306256432
False
4306256240
4306256240
True
Here's my code in Mac Terminal, which I think is the ideal result
Python 3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52)
Type "help", "copyright", "credits" or "license" for more information.
>>> b=257
>>> c=257
>>> print(id(b))
4351554224
>>> print(id(c))
4351554096
>>> print(b is c)
False
Reference: [1]"is" operator behaves unexpectedly with integers