Relational calculation methods of the Set, and relational calculation methods of the Set

Source: Internet
Author: User

Relational calculation methods of the Set, and relational calculation methods of the Set

A = [4, 5, 6, 7, 8]

A = set ()
# A. add ('adfaaaa') # add as only one element
# A. update ([121212]) # It must be an iterative object to add
# Print ()
B = {1, 2, 3, 4, 5}

# Print the total elements at the intersection of the Set
Print (a. intersection (B) # method 1
Print (a & B) # method 2

{4, 5}

# Print out all the elements of the Two Sets and remove duplicates from the union of the Set
Print (a. union (B) # method 1
Print (a | B) # method 2

{1, 2, 3, 4, 5, 6, 7, 8}

# The difference set of the Set uses a as the reference object to find the elements that a does not have B
Print (a. difference (B) # method 1
Print (a-B) # method 2

{8, 6, 7}

# Find out the elements of a and B in the inverse difference set of the set.
Print (a. effecric_difference (B) # method 1
Print (a ^ B) # method 2

{1, 2, 3, 6, 7, 8}


# The parent set of the set only returns True or False to determine whether a is a B's parent set, that is, whether all element a of B has an element a and B does not.
Print (a. issuperset (B) # method 1
Print (a> B) # method 2

False

# The subset of the set determines whether a is a B's sub-set, that is, whether all elements B of a have, and B has elements that a does not have.
Print (a. issubset (B) # method 1
Print (a <B) # method 2

False

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.