标签:
#深浅拷贝
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)
标签:
原文地址:http://www.cnblogs.com/bk770466199/p/5844499.html