首页 > 代码库 > 赋值,copy和deepcopy

赋值,copy和deepcopy

python的复制,拷贝,和深拷贝。

>>> a=[23,3]
>>> b=a
>>> b.append(234)
>>> a
[23, 3, 234]
>>> import copy
>>> a=[23,3,3,[23,3]]
>>> b= copy.copy(a)
>>> b
[23, 3, 3, [23, 3]]
>>> b[3].append(34)
>>> a
[23, 3, 3, [23, 3, 34]]
>>> b
[23, 3, 3, [23, 3, 34]]

赋值,copy和deepcopy