I was struggling to find why does
a = [1, 2, 3]
a = b
b = b + [1]
return a different value as compared to
b += [1]
Looking into the source code, everything became clear. The + operator returns a pointer to a new list np containing all the elements from a and b, while += merely appends and returns a pointer to the original list
I was struggling to find why does a = [1, 2, 3] a = b b = b + [1] return a different value as compared to b += [1]
Looking into the source code, everything became clear. The + operator returns a pointer to a new list np containing all the elements from a and b, while += merely appends and returns a pointer to the original list