def test(): a = [1,2,3] def test2(): a += [4,5] test2() print a test() In my thoughts, a += [4,5] would be equivalent to a.extend cus it is in-place Concatenating two lists - difference between '+=' and extend()
However, use += triggers an error, but extend works fine.
Am I wrong?
Update
I believe I found the reason.
operator.iadd(a, [4,5]) works fine.
So I believe internally a+=[4,5] is interpreted as a = operator.iadd(a, [4,5]), and here comes the assignment.