In Python, I assumed that a += b is equivalent to a = a + b , but when a and b is a list, there is a difference in whether creates a new object.
Could anyone tell me the reason?
Here's my code in Python 3.8:
a = [1]
print(id(a))
a += [2]
print(id(a))
a = [1]
print(id(a))
a = a + [2]
print(id(a))
140307711202952
140307711202952
140307711207176
140307711203336