我已經與列出該實驗是p= p+i
不同然後p += i
例如,當注意到:差和+ =
test = [0, 1, 2, 3,]
p = test
test1 = [8]
p = p + test1
print test
在上面的代碼test
打印出到原始值的[0, 1, 2, 3,]
但是,如果我在下面
test = [0, 1, 2, 3,]
p = test
test1 = [8]
p += test1
print test
切換
p = p + test1
與
p += test1
作爲
test
現在等於[0, 1, 2, 3, 8]
不同值的原因是什麼?
以下是對此的深入解答:http://stackoverflow.com/questions/2347265/what-does-plus-equals-do-in-python –
參見http://stackoverflow.com/a/ 4773111/2314737和http://stackoverflow.com/a/2027311/2314737 – user2314737
另請參見[在列表中組合元素:看起來像python以兩種不同的方式處理相同的項目,我不知道爲什麼](http:// stackoverflow.com/q/17240162)和[Python是什麼時候「i + = x」與「i = i + x」不同?](http://stackoverflow.com/q/15376509) –