python取两个set的并集、交集、差集

示例:对于以下两个set

x = set([1,2,3])
y = set([2,3,4])

1. 并集

x | y
或
x.union(y)

2. 交集

x & y
或
x.intersection(y)x.intersection(y)

3. 差集

x - y
或
x.difference(y)

猜你喜欢

转载自blog.csdn.net/weixin_44388689/article/details/120370706