python 合集set,交集,并集,差集,对称差集别搞混
有集合 x与y
x = {1,2,3,4,5}
y = {4,5,6,7,8}
x和y的交集为 {4,5}
x和y的对称差集{1, 2, 3, 6, 7, 8}
x和y的并集{1, 2, 3, 4, 5, 6, 7, 8}
x与y的差集(x.difference(y)){1, 2, 3}
y与x的差集(x.difference(y)){8, 6, 7}
![](https://img2018.cnblogs.com/blog/1644071/201904/1644071-20190409212026544-487653452.png)
有集合 x与y
x = {1,2,3,4,5}
y = {4,5,6,7,8}
x和y的交集为 {4,5}
x和y的对称差集{1, 2, 3, 6, 7, 8}
x和y的并集{1, 2, 3, 4, 5, 6, 7, 8}
x与y的差集(x.difference(y)){1, 2, 3}
y与x的差集(x.difference(y)){8, 6, 7}
![](https://img2018.cnblogs.com/blog/1644071/201904/1644071-20190409212026544-487653452.png)