python基础七之copy
浅拷贝
没有嵌套,则copy后完全不同,有嵌套,则copy后本体不同,嵌套相同。
l1 = [1, 2, [4, 5, 6], 3] l2 = l1.copy() print(l1 is l2) # False print(l1[2] is l2[2]) # True
深拷贝
copy后完全不同,嵌套也不同。
import copy l1 = [1, 2, [4, 5, 6], 3] l2 = copy.deepcopy(l1) print(l1 is l2) # False print(l1[2] is l2[2]) # False