Python variable set

Source: Internet
Author: User

List is a combination that allows content to be duplicated

A tuple is a combination that allows content to be duplicated

Dict

Set is a combination that does not allow duplication of content, and the contents of the set are arbitrary, so they cannot be listed by index

Set creation:

#The first wayA=set (["a","b","C"])Print(a)#The second wayA=set () A.add ("a") A.add ("b")Print(a)#The Third Way, this way is not a={}a={"a","b","C"}Print(a)
#conversion of Set seta=["AWE","Weg","Dawqgg"]c=set (a)Print(c) B="Chenshuagege"D=Set (b)Print(d) Al=("233","34455") AW=set (AL)Print(AL)

Common methods of Set:

 #  difference means that content B in a is not, But this does not modify the value of a itself, but instead pays ret the  a={ 12  Span style= "COLOR: #800000" > ", "  14   ", "  234   " }b  ={ " 12   ", "     " }ret  = a.difference (b)  print  (ret) 
 #  difference_update means that content B in a is not, executed, Modifies the contents of a  a={ 12   ", "  14   ", "  234   " }b  ={ " 12   ", "     }a.difference_update (b)  print  (a) 
# Discard is the same as remove, but discard will not give an error, and remove will b={1,23}b.discard (1)print(b)
# take the intersection of the two b={1,23}a={23,5}ret=b.intersection (a)print(ret)
# take the intersection of the two, Intersection_update will change the content of B b={1,23}a={23,5}b.intersection_update (a) Print (b)
b={1,23}a={23,5}# returns False if A and B have a collection, and returns True ret= B.isdisjoint if there is no collection( A)print(ret)
b={1,23,5}a={23,5}#issuperset Description B is the father of a if it is output true if not output falseret=  B.issuperset (a)print(ret)
b={1,23,5}a={23,5}#B is the child of a, if it is true, output false ifit is not ret=  B.issubset (a)print(ret)
# pop () returns the item that was deleted a={"a","b","C  "}ret=a.pop ()print(a)

Python variable set

Related Article

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.