0
a += b is not always a = a + b?
Operator "in-place: +=" gives an unexpected result. Why is that? Please comment the following code. https://code.sololearn.com/cJfDR5W6knpc/?ref=app
2 Answers
0
This question was asked by Pratik Joshi, but without code.
0
Lists are always passed by reference. If you append something to list1 with +=, list2 is still a reference to list1.
With = you define a new list1, while list2 keeps the reference to the old list.