Python Learning day08

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.