深浅拷贝
浅拷贝:只拷贝一层
1 s2=['alex',1,(1,2,3)] 2 s3=s2.copy() 3 print(s3) 4 5 s2[0]='conghui' 6 print(s2) 7 print(s3) 8 9 夫妻银行关联账户 10 husband=['xiaochen',159,[15000,9000]] 11 wife=husband.copy() 12 print(wife) 13 wife[0]='conghui' 14 wife[1]=357 15 16 husband[2][1]-=3000 #取出3000 17 print(wife)
深拷贝:克隆一份
1 import copy 2 3 husband=['xiaohu',159,[15000,9000]] 4 xiaosan=copy.deepcopy(husband) 5 xiaosan[0]='biaozi' 6 xiaosan[1]=666 7 xiaosan[2][1]-=1999 8 print(xiaosan)