set集合下的函数:
difference()可以求差集
>>> set(a).difference(set(b))
set([4, 5, 6, 7, 8, 9])
>>> a
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> b
[1, 2, 3]
>>> set(a).difference(set(b))
set([4, 5, 6, 7, 8, 9])union()可以求并集
>>> set(a).union(set(b))
set([1, 2, 3, 4, 5, 6, 7, 8, 9])intersection()可以求交集
>>> set(a).intersection(set(b))
set([1, 2, 3])
本文详细介绍了Python中set集合的基本操作,包括求差集、并集及交集的方法。通过具体的代码示例展示了如何使用difference()、union()和intersection()函数进行集合运算。
1987

被折叠的 条评论
为什么被折叠?



