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)