浅copy与深copy的理解
浅copy格式:
lt.copy()
浅copy是复制一份与列表(字典,集合)id相同的列表(字典,集合),id未改变
a = [1,2,3,['xiaohao','guoqi'],4]
b = a.copy
b[2] = 'A'
print(b)
[1,2,'A',['xiaohao','guoqi'],4]
c = b.copy
c[3][1] = '郭琪'
print(c)
[1,2,3,['xiaohao','郭琪'],4]
深copy格式:
copy.deepcopy(lt)
a = [1,2,3,['xiaohao','guoqi'],4]
b = a.copy
b[2] = 'A'
print(b)
[1,2,'A',['xiaohao','guoqi'],4]
c = b.copy
c[3][1] = '郭琪'
print(c)
[1,2,'A',['xiaohao','郭琪'],4]
浅copy与深copy的理解最先出现在Python成神之路。
共有 0 条评论