title: If Python strings are immutable, why does it keep the same id if I use += to append to it?
body: <p>Strings in Python are immutable, which means the value cannot be changed. However, when appending to the string in the following example, it looks like the original string memory is modified since the id remains the same:</p>
  <pre><code>&gt;&gt;&gt; s = 'String'
  &gt;&gt;&gt; for i in range(5, 0, -1):
  ...     s += str(i)
  ...     print(f&quot;{s:&lt;11} stored at {id(s)}&quot;)
  ... 
  String5     stored at 139841228476848
  String54    stored at 139841228476848
  String543   stored at 139841228476848
  String5432  stored at 139841228476848
  String54321 stored at 139841228476848
  </code></pre>
  <p>Conversely, in the following example, the id changes:</p>
  <pre><code>&gt;&gt;&gt; a = &quot;hello&quot;
  &gt;&gt;&gt; id(a)
  139841228475760
  &gt;&gt;&gt; a = &quot;b&quot; + a[1:]
  &gt;&gt;&gt; print(a)
  bello
  &gt;&gt;&gt; id(a)
  139841228475312
  </code></pre>