可能重复:
加号等于(+=)在 Python 中做了什么?
我注意到一个奇怪的问题:
l1 = ['1', '2', '3']
l2 = l1
item = l2.pop(0)
# the pop operation will effect l1
print l1
l2 = l2 + [item]
# why "l2 = l2 + [item]" does't effect l1 while "l2 += [item]" does.
print l2
print l1
输出是:
['2', '3']
['2', '3', '1']
['2', '3']
但如果我l2 = l2 + [item]
变成l2 += [item]
,输出将是:
['2', '3']
['2', '3', '1']
['2', '3', '1']