Python Set isdisjoint() 方法

Python3 列表 Python 集合


描述

isdisjoint() 方法用於判斷兩個集合是否包含相同的元素,如果沒有返回 True,否則返回 False。。

語法

isdisjoint() 方法語法:

set.isdisjoint(set)

參數

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

返回值

返回布爾值,如果不包含返回 True,否則返回 False。

實例

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

實例 1

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

輸出結果為:

True

如果包含返回 False:

實例 1

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

輸出結果為:

False

Python3 列表 Python 集合