新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythondifference_update()
python 中的difference_update()函數(shù)有助于集合更新。它首先找出給定的兩個(gè)集合之間的集合差。并用集合差的結(jié)果元素更新第一個(gè)集合。集合差給出了一個(gè)新的集合,它包含只存在于第一個(gè)集合中的元素,而不存在于第二個(gè)集合中。

創(chuàng)新互聯(lián)是一家以網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)、品牌設(shè)計(jì)、軟件運(yùn)維、成都網(wǎng)站推廣、小程序App開發(fā)等移動(dòng)開發(fā)為一體互聯(lián)網(wǎng)公司。已累計(jì)為紙箱等眾行業(yè)中小客戶提供優(yōu)質(zhì)的互聯(lián)網(wǎng)建站和軟件開發(fā)服務(wù)。
**A.difference_update(B)** #where A & B are sets
差異 _ 更新()參數(shù):
difference()函數(shù)將 set 作為其參數(shù)。在此方法調(diào)用之后,集合 A 將被更新為 A-B。集合 B 保持不變。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 設(shè)置 | 要檢查差異的集合 | 需要 |
差異 _ 更新()返回值
這個(gè)方法不返回值。它用一組不同的值更新原始集。
Python 中的difference_update()方法示例
示例 difference _ update()在 Python 中是如何工作的?
A = {1, 2, 3, 4, 6}
B = {5, 2, 4, 7}
# Before update
print('A = ', A)
result = A.difference_update(B)
# After update
print('A = ', A)
print('B = ', B)
print('result = ', result)
輸出:
# Before update
A = {1, 2, 3, 4, 6}
# After update
A = {1, 3, 6}
B = {5, 2, 4, 7}
result = None 示例 Python 中difference_update()的工作原理?
A = {'a', 'b', 'c', 'd'}
B = {'c', 'f', 'd'}
# Before update
print('A = ', A)
result = A.difference_update(B)
# After update
print('A = ', A)
print('B = ', B)
print('result = ', result)
輸出:
# Before update
A = {'a', 'b', 'c', 'd'}
# After update
A = {'a', 'b'}
B = {'c', 'd', 'f'}
result = None 當(dāng)前文章:創(chuàng)新互聯(lián)Python教程:Pythondifference_update()
分享路徑:http://www.dlmjj.cn/article/ccsoeso.html


咨詢
建站咨詢
