Python 3 教程 Python Set isdisjoint() 方法

vachon · 2022-03-14 15:03:49 · 热度: 8

描述

isdisjoint() 方法用于判断两个集合是否包含相同的元素,如果没有返回 True,否则返回 False。。

语法

isdisjoint() 方法语法:

set.isdisjoint(set)

参数

  • set -- 必需,要比较的集合

返回值

返回布尔值,如果不包含返回 True,否则返回 False。

实例

判断集合 y 中是否有包含 集合 x 的元素:

实例 1

x = {"apple", "banana", "cherry"} y = {"google", "codercto", "facebook"} z = x.isdisjoint(y) print(z)

输出结果为:

True

如果包含返回 False:

实例 1

x = {"apple", "banana", "cherry"} y = {"google", "codercto", "apple"} z = x.isdisjoint(y) print(z)

输出结果为:

False

查看更多 Python 集合 内置函数

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册