Python 集合 isdisjoint() 方法
示例
如果集合 x
中沒有專案存在於集合 y
中,則返回 True
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "facebook"}
z = x.isdisjoint(y)
print(z)
自己動手試一試 »
定義和用法
isdisjoint()
方法返回 True,如果兩個集合中沒有共同專案,否則返回 False。
語法
set.isdisjoint(set)
引數值
引數 | 描述 |
---|---|
set | 必需。用於查詢相等元素的集合 |
更多示例
示例
如果兩個集合中沒有共同專案會怎樣?
如果兩個集合中存在一個或多個共同專案,則返回 False
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.isdisjoint(y)
print(z)
自己動手試一試 »