标签:== -- 也会 imp int 创建 复制 字典 pre
# __author: "ZXYang"
# date: 2020/4/7
# s1 = [1, 2, 3, ‘aa‘, ‘bb‘, [5, 6]]
# s2 = s1.copy()
#
# # s2[0] = 11
# s2[5][1] = 66 # --- 有列表/字典,影响原有数据 (影响第一层) ====》 浅拷贝
# print(s1)
#
# print(s2)
import copy
husband = [‘li‘, ‘411000‘, [10000, 6000]]
# wife = husband.copy() # == xiaosan = copy.copy(husband) xiaosan[2][1] = 1000
wife = copy.copy(husband) # copy.copy() 浅拷贝(有可变类型的数据),复制的不彻底
wife[2][1] = 4000
san = copy.deepcopy(husband)
husband[2][0] = 20000
# san[0] = "du"
# san[2][1] -= 1000
print(wife)
print(husband)
print(san)
"""
[‘li‘, ‘411000‘, [20000, 4000]]
[‘li‘, ‘411000‘, [20000, 4000]]
[‘li‘, ‘411000‘, [10000, 4000]]
浅拷贝:复制时,被拷贝的数据有可变类型,【引用】(引用数据变化,也会随之变化)。
深拷贝:复制时,被拷贝的数据会【重新创建一份】,拷贝更加彻底。
"""
标签:== -- 也会 imp int 创建 复制 字典 pre
原文地址:https://www.cnblogs.com/zxy01/p/14160963.html