I am using Visual Studio Code's Jupyter Notebook on Windows, with Python version 3.9.13 and CPython implementation. The result of two code blocks below are different.
a = 257
b = 257
print(a is b) # False
if True:
a = 257
b = 257
print(a is b) #True
I understood that the integer 257 is not interned, which means that I expected the output to be False. However, when I added one indentation, the output became True. I tested this using both for and while loops instead of an if statement, and the result was the same. Additionally, I tested this on the terminal, and the result was also the same. However, when I tested this in a .py file, both results were True.
Thank you.