Python Set and relationship testing

Source: Internet
Author: User
#!/usr/bin/env python#_*_ coding:utf-8 _*_# defines two sets of data for the relationship test x = {1,2,3,4}y = {3,4,5,6} #交集测试 #x data is in Y too? Print x & y# or X.intersection (y) #并集测试 # Go heavy, remove the repetition and add it together. Print X | y# or X.union (y) #差集测试 # in X, but there is no print x-y# in Y or x.difference (y) #对称差集 # Remove the values of x and Y, and none of them, all in one print x ^ y# or X.symmetric_difference (y) #子集测试 is #x a subset of y? No, because neither of them is fully contained, either returns True, or returns Falseprint X.issubset (y) #小栗子 #z is a subset of x? Either returns TRUE or returns Falsez = {1,2,4}print z.issubset (x) #x是否包含yprint x.issuperset (y)


This article is from the "Fa&it-Q Group: 223843163" blog, please be sure to keep this source http://freshair.blog.51cto.com/8272891/1869692

Python Set and relationship testing

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.