# 赋值运算 # l1 = [1,2,3] # l2 = l1 # l1.append(‘a‘) # print(l1,l2)
浅copy
# l1 = [1,2,3] # l2 = l1.copy() # print(l1,l2) # print(id(l1),id(l2)) # l2.append(‘a‘) # print(l1,l2)
# l1 = [1,2,[4,5,6],3] # l2 = l1.copy() # print(l1,id(l1)) # print(l2,id(l2)) # l1.append(‘a‘) # print(l1,l2) # l1[2].append(‘a‘) # print(l1,l2) # print(id(l1[2])) # print(id(l2[2]))
深copy
import copy l1 = [1,2,[4,5,6],3] l2 = copy.deepcopy(l1) print(l1,id(l1)) print(l2,id(l2)) l1[2].append(‘a‘) print(l1,l2) print(l1,id(l1)) print(l2,id(l2))
原文:https://www.cnblogs.com/seven-wenzi/p/14608253.html