For immutable objects, inplace operation such as “+=” creates a new object and assign the variable to the newly created object.
= "test"
s = id(s)
old_id += " another test"
s == id(s) #=> False old_id
But for mutable objects, it doesn’t create a new object. It extends/updates the existing object.
= [1]
l = id(l)
old_id += [2]
l == id(l) #=> True old_id