新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonintersection_update()
python 中的交集_update()函數(shù)有助于集合更新。它首先找出給定集合的交集。并用集合交集的結(jié)果元素更新第一個集合。集合交集給出了包含所有給定集合中公共元素的新集合。

我們提供的服務(wù)有:成都做網(wǎng)站、成都網(wǎng)站制作、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、阜寧ssl等。為近1000家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學管理、有技術(shù)的阜寧網(wǎng)站制作公司
**A.intersection_update(*other_sets)** #where A is a set of any iterables, like strings, lists, and dictionaries
交集 _ 更新()參數(shù):
intersection_update()函數(shù)可以采用許多集合參數(shù)進行比較(*表示),并用逗號分隔這些集合。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| A | 在中搜索相等項目并更新的集合 | 需要 |
| 其他集 | 另一組用于搜索相等的項目 | 可選擇的 |
交集 _ 更新()返回值
此方法不返回值。它會更新原始設(shè)置。
結(jié)果= A.intersection_update(B,C)考慮這一點,這里的結(jié)果將是無。A 將是 A、B、c 的交匯點,而 B & C 保持不變。
Python 中的交集_update()方法示例
示例 intersection _ update()在 Python 中是如何工作的?
A = {'a', 'b', 'c', 'd'}
B = {'c', 'e', 'f', 'a'}
result = A.intersection_update(B)
print('result =', result)
print('A =', A)
print('B =', B)
輸出:
result = None
A = {'a', 'c'}
B = {'c', 'e', 'f', 'a'}
示例 2:帶有兩個參數(shù)的 Python 方法交集_update()
A = {'a', 'b', 'c', 'd'}
B = {'c', 'e', 'f', 'a'}
C = {'d', 'f', 'a', 'g'}
result = C.intersection_update(B, A)
print('result =', result)
print('C =', C)
print('B =', B)
print('A =', A)
輸出:
result = None
C = {'a'}
B = {'c', 'e', 'f', 'a'}
A = {'a', 'b', 'c', 'd'} 網(wǎng)頁標題:創(chuàng)新互聯(lián)Python教程:Pythonintersection_update()
文章起源:http://www.dlmjj.cn/article/coiisdo.html


咨詢
建站咨詢
