新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonupdate()
python 中的update()函數(shù)通過添加來自另一個集合(即來自給定 iterable)的元素來幫助更新該集合。如果兩個集合中存在相同的元素,則只放置一個實例。

創(chuàng)新互聯(lián)公司自成立以來,一直致力于為企業(yè)提供從網(wǎng)站策劃、網(wǎng)站設計、網(wǎng)站設計制作、成都網(wǎng)站設計、電子商務、網(wǎng)站推廣、網(wǎng)站優(yōu)化到為企業(yè)提供個性化軟件開發(fā)等基于互聯(lián)網(wǎng)的全面整合營銷服務。公司擁有豐富的網(wǎng)站建設和互聯(lián)網(wǎng)應用系統(tǒng)開發(fā)管理經(jīng)驗、成熟的應用系統(tǒng)解決方案、優(yōu)秀的網(wǎng)站開發(fā)工程師團隊及專業(yè)的網(wǎng)站設計師團隊。
**A.update(iterable)** #where iterable such as list, set, dictionary, string, etc.
更新()參數(shù):
update()函數(shù)接受一個可迭代的參數(shù)。如果給定的表是一個列表、元組或字典,這個函數(shù)會自動將其轉(zhuǎn)換成一個集合,并將元素添加到該集合中。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 可重復的 | 當前集合中的可迭代插入 | 需要 |
更新()返回值
update()函數(shù)不返回值,它只是通過向現(xiàn)有集合中添加元素來更新它。該函數(shù)可以接受多個用逗號分隔的可重復參數(shù)。
Python 中update()方法的示例
示例 Python set update()是如何工作的?
X = {'x', 'y'}
Y = {5, 4, 6}
result = X.update(Y)
print('X =', X)
print('result =', result)
輸出:
A = {'x', 5, 4, 6, 'y'}
result = None
示例 2:如何使用update()向 Set 添加字符串和字典元素?
alphabet_str = 'abc'
num_set = {1, 2}
# add elements of the string to the set
num_set.update(alphabet_str)
print('Numbers Set =', num_set)
dict_info= {'key': 1, 'lock' : 2}
num_set = {'a', 'b'}
# add keys of dictionary to the set
num_set.update(dict_info)
print('Numbers Set=', num_set)
輸出:
Numbers Set = {'c', 1, 2, 'b', 'a'}
Numbers Set = {'key', 'b', 'lock', 'a'} 文章題目:創(chuàng)新互聯(lián)Python教程:Pythonupdate()
轉(zhuǎn)載來于:http://www.5511xx.com/article/cceepps.html


咨詢
建站咨詢
