深浅拷贝
#_author:Administrator
#date:2019/10/31
#深浅拷贝
#浅拷贝:只copy 第一层
#深拷贝:全部克隆
#(1)
a=[1,'laitongxing',[1,2,3]]
print(a)#[1, 'laitongxing', [1, 2, 3]]
s=a.copy()
print(s)#[1, 'laitongxing', [1, 2, 3]]
s[0]=2
print(s)#[2, 'laitongxing', [1, 2, 3]]
print(a)#[1, 'laitongxing', [1, 2, 3]]
#(2)
b=[[2,3],'star','yuwei']
s1=b.copy()
print(s1)#[[2, 3], 'star', 'yuwei']
s1[1]='linux'
print(b)#[[2, 3], 'star', 'yuwei']
print(s1)#[[2, 3], 'linux', 'yuwei']
s1[0][1]=8
print(s1)#[[2, 8], 'linux', 'yuwei']
print(b)#[[2, 8], 'star', 'yuwei']
#(3)
m1=[[1,2],2,3]
m2=m1.copy()
m2[1]='abc'
print(m1)#[[1, 2], 2, 3]
print(m2)#[[1, 2], 'abc', 3]
#2.银行账户关联(浅拷贝)
import copy
husband=['star','001',[15000,9000]]
wife=husband.copy()#shallow copy
wife[0]='wei'
wife[1]='002'
xiaosan=copy.deepcopy(husband)
xiaosan[0]='weina'
xiaosan[1]='003'
husband[2][1]-=3000
xiaosan[2][1]-=1999
print(wife)#['wei', '002', [15000, 6000]]
print(xiaosan)#['weina', '003', [15000, 7001]] 完全独立
print(husband)#['star', '001', [15000, 6000]]