我注意到一个奇怪的问题:
输出结果为:
可能是重复问题:
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']