aset = {
1, 2, 3}
aset.update() # 不傳參數是可以的,保持原樣返回
print(aset) # {1, 2, 3}
aset.update({
4, 5}) # 合並集合
print(aset) # {1, 2, 3, 4, 5}
aset.update({
6, 7}, {
8, 9}) # 一次合並多個集合,之後的類型只要可以合並就可以多個,而且不同類型可以混用
print(aset) # {1, 2, 3, 4, 5, 6, 7, 8, 9}
aset.update({
'a': 10}) # 更新字典只取鍵
print(aset) # {1, 2, 3, 4, 5, 6, 7, 8, 9, 'a'}
bset={
'b','c'}
bset.update(['d']) # 用列表更新(元組同理)
print(bset) # {'b', 'c', 'd'}
bset.update('ef1') # 用字符串更新
print(bset) # {'b', 'c', 'd', 'e', 'f', '1'}
bset.update(2) # 但是單獨的數字不行,update傳入的需要是可迭代對象
print(bset) # TypeError
It seems that there is a hot question. Will Python become a common programming tool for public office in the future?
Python Dealing with office aut
CTRL enter Python in vscode executes the current line and automatically jumps to the next line
VScode in ,R Language and Juli