python 学习笔记 copy
浅copy
>>> a=[1,2,3,[4,5,6]]
>>> a
[1, 2, 3, [4, 5, 6]]
>>> a[3].append(7)
>>> a
[1, 2, 3, [4, 5, 6, 7]]
>>> b=a[:]
>>> b
[1, 2, 3, [4, 5, 6, 7]]
>>> id(b)
5210280
>>> id(a)
5139592
>>> id(a[3])
5136912
>>> id(b[3])
5136912
>>> b[3].append(4)
>>> b
[1, 2, 3, [4, 5, 6, 7, 4]]
>>> a
[1, 2, 3, [4, 5, 6, 7, 4]]
深COPY
>>> import copy
>>> c=copy.deepcopy(a)
>>> c
[1, 2, 3, [4, 5, 6, 7, 4]]
>>> c[3].append(4)
>>> c
[1, 2, 3, [4, 5, 6, 7, 4, 4]]
>>> a
[1, 2, 3, [4, 5, 6, 7, 4]]
>>>