列表-Ⅴ-拷贝深浅
本帖最后由 BrightXiong 于 2023-3-1 21:37 编辑>>> # 浅拷贝:利用列表的从copy()方法、切片来实现
>>> x = [, , ]
>>> y = x.copy()
>>> x = 0
>>> x
[, , ]
>>> y
[, , ]
>>> # 将对象拷贝时,也将对象中所有引用对象一并进行拷贝
>>> # 深拷贝:利用copy模块的deepcopy()函数来实现
>>> a = [, , ]
>>> import copy
>>> b = copy.deepcopy(a)
>>> a = 0
>>> a
[, , ]
>>> b
[, , ]
页:
[1]