Python中 "+=" 使用時的注意事項

代碼1:code

>>> l1=range(3)
    >>> l2=l1
    >>> l2+=[4]
    >>> l1
    [0, 1, 2, 4]
    >>> l2
    [0, 1, 2, 4]

代碼2:get

>>> l2=l1
>>> l2=l2+[4]
>>> l1
[0, 1, 2]
>>> l2
[0, 1, 2, 4]

Why does += behave unexpectedly on lists?io

相關文章
相關標籤/搜索