set(集合)
作者:互联网
#交集
a = set([1,2,3,4,5])
b = set([4,5,6,7,8])
print(a.intersection(b))
print(a & b)
#并集
print(a.union(b)) #第一种
print(a|b) #第二种
#差集
print(a.difference(b))
print(a - b)
print(b.difference(a))
print(b - a)
#对称差集
print(a.symmetric_difference(b))
print(a ^ b)
#超集
print(a.issuperset(b))
print(a > b)
#子集
print(a.issubset(b))
print(a < b)
标签:set,并集,issubset,差集,print,集合,difference 来源: https://www.cnblogs.com/Mis168/p/16517142.html