In a Python 3.8.5 shell I have :
>>> id([])
140370451791744
>>> id([])
140370451791744
>>> id([])
And in IPython 7.18.1 running Python 3.8.5 I have :
In [1]: id([])
Out[1]: 139870334633536
In [2]: id([])
Out[2]: 139870334633152
This leads me to the following question : why IPython behavior is different than python's one ?
This is related to a previous question I had Which interpreter is used by ipython? showing that both IPython and Python interactive shells use the same python implementation which is CPython.
To me, IPython is only a shell thing and should just forward interpretation of python's code to the underlying interpreter which is the same as the Python's one. Hence, the result of evaluating the same code should be the same (not the address of the object of course, but the fact of reusing the same one)
Note: I can easily imagine some reasons explaining why sometimes the interpreter is able to reuse the same memory location for a new object and sometimes not but I can't explain why the behaviors differs here since both use the same implementation.
Is this a duplicate: to people asking if this is a duplicate of How unique is Python's id()? the answer is clearly no and I tried to do my best to explain why above. Maybe it's not clear ?