首页 > 代码库 > 【今日代码段】--Day4

【今日代码段】--Day4

#深浅拷贝

import copya = [[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)

 

【今日代码段】--Day4