【今日代码段】--深浅拷贝
#深浅拷贝
import copy a = [[1,2],"zhangw","haha"] b = copy.copy(a) #浅拷贝, 只复制第一次地址,固定地址复制,可变地址共享 b2 = copy.deepcopy(a) #深拷贝,完全复制一份 choose = int(input("请选择深浅,1深,2浅:")) if choose == 2: b[1] = "zhangwei" b[0][1] = 22 print("b=%s"%b) print("a=%s"%a) else: b2[1] = "zhangwei" b2[0][1] = 22 print("b2=%s"%b2) print("a=%s"%a)
人生短短数十载,经不起几次重头再来