difference between adding lists in python with + and +=

Viewed 201

I've noticed when experimenting with lists that p= p+i is different then p += i For example:

test = [0, 1, 2, 3,]
p = test
test1 = [8]
p = p + test1
print test

In the above code test prints out to the original value of [0, 1, 2, 3,]

But if I switch p = p + test1 with p += test1 As in the following

test = [0, 1, 2, 3,]
p = test
test1 = [8]

p += test1

print test

test now equals [0, 1, 2, 3, 8]

What is the reason for the different value?

3 Answers
Related