新聞中心
python 中的isdisjoint()函數(shù)有助于檢查給定的兩個(gè)集合是否不相交。如果集合不相交,則返回真,否則返回假。不相交意味著這兩個(gè)集合沒有共同的元素。

創(chuàng)新互聯(lián)建站長期為超過千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為瀘溪企業(yè)提供專業(yè)的成都網(wǎng)站建設(shè)、成都做網(wǎng)站,瀘溪網(wǎng)站改版等技術(shù)服務(wù)。擁有十載豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
**set_a.isdisjoint(set_b)** #where parameter may be list, tuple, dictionary, and string
isdisjoint()參數(shù):
isdisjoint()函數(shù)接受一個(gè)參數(shù)。這個(gè)方法會(huì)自動(dòng)將給定的可迭代參數(shù)轉(zhuǎn)換成一個(gè)集合,以檢查它是否不相交。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 設(shè)置 | 要在其中搜索相等項(xiàng)目的集合 | 需要 |
isdisjoint()返回值
此方法返回一個(gè)布爾值 true 或 false。我們也可以說,如果兩個(gè)集合的交集是一個(gè)空集,它將是一個(gè)不相交的集合。
| 投入 | 返回值 | | 如果集合不相交 | 真實(shí)的 | | 如果集合不是不相交的 | 錯(cuò)誤的 |
Python 中isdisjoint()方法的示例
示例isdisjoint()在 Python 中是如何工作的?
A = {'a', 'b', 'c', 'd'}
B = {'e', 'f', 'g'}
C = {'b', 'h', 'i'}
print(' A and B disjoint?', A.isdisjoint(B))
print(' A and C disjoint?', A.isdisjoint(C))
輸出:
A and B disjoint? True
A and C disjoint? False 示例 2:使用其他 iterables 作為參數(shù)使用isdisjoint()
A = {1, 2, 3, 4}
B = [5, 3, 6]
C = '3mn7'
D ={1 : 'a', 2 : 'b'}
E ={'a' : 1, 'b' : 2}
print('A and B disjoint?', A.isdisjoint(B))
print('A and C disjoint?', A.isdisjoint(C))
print('A and D disjoint?', A.isdisjoint(D))
print('A and E disjoint?', A.isdisjoint(E))
輸出:
A and B disjoint? False
A and C disjoint? False
A and D disjoint? False
A and E disjoint? True 新聞標(biāo)題:創(chuàng)新互聯(lián)Python教程:Pythonisdisjoint()
URL網(wǎng)址:http://fisionsoft.com.cn/article/cdgedgs.html


咨詢
建站咨詢
