首页 › 参考手册 › 集合方法 › set.difference()

Python set.difference() 方法

描述

返回差集(在当前集合中、但不在其他集合中的元素),等价于 -。

语法

set.difference(*others)

参数

参数说明
others其他集合

返回值

新集合

实例

print({1, 2, 3, 4} - {2, 4})
以上实例输出结果为:
{1, 3}