One: Depth copy
1: Shallow copy
st = [[+],'Duke','haha']st1=st.copy ()Print(ST)Print(ST1)Print(ID (st1[0]))Print(ID (st[0]))Print(ID (st[0][1]))Print(ID (st1[0][1]))Print(ID (st[0][0]))Print(ID (st1[0][0])) st1[0][1]=3Print(ST)Print(ST1)Print(ID (st1[0]))Print(ID (st[0]))Print(ID (st[0][1]))Print(ID (st1[0][1]))Print(ID (st[0][0]))Print(ID (st1[0][0]))
The result of the execution is:
、
2: Deep copy
ImportCopyduke= ["Duke", 111,[88888,277272]]wife= Duke.copy ()#Shallow CopyWife[0] ="Xiaomi"wife[1] = 234Xaiohua= Copy.deepcopy (Duke)#Deep CopyXaiohua[0] ="Qinqin"xaiohua[1] = 567wife[2][1]-= 555xaiohua[2][1]-= 666Print(Duke)Print(wife)Print(Xaiohua)
Two: Set
#Codeing:utf-8#__author__:duke#date:2018/3/6/006#Set collection: Grouping different elements together#Create by keywords = Set ('hjsdjhjdsh')#Note that the elements of the collection must be data types that can be hasheds = List (['Dukehah','Hudshcsuh','Duke','Duke']) s= Set (s)#will automatically remove duplicate elementsPrint(s)Print(type (s))#no index, so an iterator is required to access forIinchS:Print(i)#add ElementS.add ('W')Print(s) s.update ('D')Print(s)#methods for deleting elementsS.pop () s.remove ('D') s.clear ()#del s#operator#equivalencePrint(Set ('111') ==set ('111'))#TRUEPrint(Set ('111') ==set (' One'))#False#subsetPrint(Set ('111') <set ('111w'))#TRUEPrint(Set ('111U') <set ('111w'))#False
A =Set ([1,2,3,4,5])
b =Set ([4,5,6,7])
#交集
print (a.intersection (b))
#并集
print (a.union (b))
print (A | b)
#差集
print (a.difference (b)) #in a but not in B
print (a)
Print (B.difference (a)) #in B but not in a
print (b-a)
#反向交集
print (a.symmetric_difference (b)) #对称差集
print (a ^ b)
Python Learning day08