#!/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