标签:pen 生成 key 浅拷贝 引用 bubuko pre 字典 注意
通俗的理解是:拷贝了引用,并没有拷贝内容
In [88]: a = [11,22,33]
In [89]: b = copy.copy(a)
In [90]: id(a)
Out[90]: 59275144
In [91]: id(b)
Out[91]: 59525600
In [92]: a.append(44)
In [93]: a
Out[93]: [11, 22, 33, 44]
In [94]: b
Out[94]: [11, 22, 33]
In [95]:
In [95]:
In [95]: a = (11,22,33)
In [96]: b = copy.copy(a)
In [97]: id(a)
Out[97]: 58890680
In [98]: id(b)
Out[98]: 58890680
a = "abc"
b = a[:]
d = dict(name="zhangsan", age=27)
co = d.copy()
a = list(range(10))
b = list(a)
import copy
a = (1,2,3)
b = copy.copy(a)
标签:pen 生成 key 浅拷贝 引用 bubuko pre 字典 注意
原文地址:https://www.cnblogs.com/yoyo1216/p/10119576.html