I am a little bit confused about the immutability of integers in Python and the behavior of objects with the same value having different memory IDs. As far as I know, In Python, immutable types like integers, and float are indeed passed by value. It is expected that two different integer objects with the same value could have different memory IDs because they are separate objects. However, due to optimization in Python, sometimes the interpreter may treat these objects as the same and assign them the same ID.
If there is nothing wrong with what I wrote above, here is my question. How is it determined whether to apply optimization? Why am I getting different results in the same computer and Python env?
a=5.0
b=5.0
print(a is b)
I tried it in VSCODE and Command Prompt. and I looked for the same question but couldn't see exactly same.