定义和用法
如果没有项目同时存在于不同集合中,则 isdisjoint() 方法返回 True,否则返回 False。
实例
例子1
所有集合 x 中没有项目存在于集合 y 中,则返回 True:
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "facebook"} z = x.isdisjoint(y) print(z)
运行实例 »
例子 2
如果有项目同时存在于相同中会怎么样?
如果两个集合中都存在一个或多个项目,则返回 False:
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"} z = x.isdisjoint(y) print(z)
语法
set.isdisjoint(set)
参数
返回:Python 集合