深拷贝是将对象全拷贝,包括嵌套对象 def deepcopy(cls): if isinstance(cls, dict): dct = {} for k, v in cls.items(): dct[k] = deepcopy(v) return dct elif isinstance(cls, list): li = [] for item in cls: li.append(deepcopy(item)) return li elif isinstance(cls, tuple): li…
>>> a = ['ace',['age',10]] >>> b = a[:] >>> c = list(a) >>> for item in a: ... print(id(item)) ... 140281621219736 140281621134800 >>> for item in b: print(id(item)) ... 140281621219736 140281621134800 >>…