python中集合之间的并集、交集、差集等集合之间的组合,运用函数方法和简写方法进行笔记归类,以便查询
a=set("abc")
b=set("abcde")
print("*"*20)
print("交集")
print(a&b)
print(a.intersection(b))
print("*"*20)
print("并集")
print(a|b)
print(a.union(b))
print("*"*20)
print("差集")
print(a-b)
print(a.difference(b))
print(b-a)
print(b.difference(a))
print("*"*20)
print("对称差集")
print(a.symmetric_difference(b))
print(a^b)
print(b.symmetric_difference(a))
print("*"*20)
print("子集判断")
print(a<b)
print(a.issubset(b))
print("*"*20)
print("父集判断")
print(a>b)
print(a.issuperset(b))
转载于:https://blog.51cto.com/5353088/2106556