title: AssertionError if running code in Python prompt but not if running as file
body: <p>Why trying to explain here on stackoverflow what the Python command <strong>id()</strong> does and how can it be used to reveal how Python works under the hood I had run into following strange behavior I am struggling to understand how it comes:</p>
  <pre><code>TERMINAL-PROMPT $ python3.9 -V
  Python 3.9.13
  TERMINAL-PROMPT $ cat       &quot;list_and_int_1.py&quot;
  i = 12345
  assert id(i) == id( 12345 )
  TERMINAL-PROMPT $ python3.9 &quot;list_and_int_1.py&quot;
  TERMINAL-PROMPT $ python3.9
  Python 3.9.13 (main, May 20 2022, 21:21:14) 
  [GCC 5.4.1 20160904] on linux
  Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
  &gt;&gt;&gt; i = 12345
  &gt;&gt;&gt; assert id(i) == id( 12345 )
  Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  AssertionError
  </code></pre>
  <p><strong>So my question is why there is an AssertionError if I run the Python script code from within Python prompt but not if running the code executing it from file?</strong></p>
  <p>Seeing my question closed without trying to pay attention to what it is about I suggest: <strong>PLEASE</strong> read the question.</p>
  <p><strong>I am fully aware of the issue with cached integers.</strong> So my question is <em>NOT</em> about that. My question is why in the Python prompt there is another behavior of same code compared to running that code from the file? The Python version is exactly the same. So how does it come that it gives different results depending from where it is run?</p>
  <p>My question is definitely NOT a duplicate of:
  <code>https://stackoverflow.com/questions/306313/is-operator-behaves-unexpectedly-with-integers</code> .</p>
  <p>And ... YES, I was aware of the possibility that I don't see the assertion error messages when running the file so I have checked this out and changed the assert statement in the file so that it will  raise AssertionError to see if the Error shows up in  the console and <em>it did show up</em> excluding this kind of issue from the possible reasons.</p>
  <pre><code>TERMINAL-PROMPT $ cat       &quot;list_and_int.py&quot;
  i = 12345
  assert id(i) == id( 12345 )
  TERMINAL-PROMPT $ python3.9 &quot;list_and_int.py&quot;
  TERMINAL-PROMPT $ cat       &quot;list_and_int.py&quot;
  i = 12345
  assert id(i) != id( 12345 )
  TERMINAL-PROMPT $ python3.9 &quot;list_and_int.py&quot;
  Traceback (most recent call last):
    File &quot;/home/.../list_and_int.py&quot;, line 2, in &lt;module&gt;
      assert id(i) != id( 12345 )
  AssertionError
  </code></pre>
  <p>P.S. I have seen the urge to close questions here on stackoverflow many times being sometimes myself not able to post an answer because the question was closed very fast and the reason given for closing it was a wrong one. I understand the time pressure of the modern world ... but ... this is not an excuse for not spending a short thought of why actually the question is there and what is it really about.</p>
  <p>P.S. P.S. Source: <code>https://docs.python.org/3.10/library/functions.html</code></p>
  <pre><code>id(object)
  Return the “identity” of an object. 
  This is an integer which is guaranteed to be unique and constant
  for this object during its lifetime. Two objects with 
  non-overlapping lifetimes may have the same id() value.
      
  </code></pre>
  <p><strong>CPython implementation detail: This is the address of the object in memory.</strong></p>
  <p>So is this documentation WRONG? Does the id() not give an insight of different memory area if the id()s are different? Is the same id() possible when the objects are stored at different positions in memory?</p>