Consider the following example:
(Python 3.7.2)
>>> a = '1'
>>> id(a)
4364850768
>>> a += '2'
>>> id(a)
4365285672
>>> a += '3'
>>> id(a)
4365285672
My understanding is that when a character is appended to string a
, a new object is created and the contents of the old object are copied over with the new character added. This does seem to be the case when 2
is appended as the ids change, but this does not seem to be the case when 3
is appended. I'm looking for some clarification on why the ids don't change the second time.