程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Update method of Python collection

編輯:Python
aset = {
1, 2, 3}
aset.update() # It is OK not to pass parameters , Return as is 
print(aset) # {1, 2, 3}
aset.update({
4, 5}) # Merge sets 
print(aset) # {1, 2, 3, 4, 5}
aset.update({
6, 7}, {
8, 9}) # Merge multiple sets at once , The following types can be multiple as long as they can be merged , And different types can be mixed 
print(aset) # {1, 2, 3, 4, 5, 6, 7, 8, 9}
aset.update({
'a': 10}) # Updating the dictionary only takes keys 
print(aset) # {1, 2, 3, 4, 5, 6, 7, 8, 9, 'a'}
bset={
'b','c'}
bset.update(['d']) # Update with list ( The same is true for tuples )
print(bset) # {'b', 'c', 'd'}
bset.update('ef1') # Update with string 
print(bset) # {'b', 'c', 'd', 'e', 'f', '1'}
bset.update(2) # But individual numbers don't work ,update The needs passed in are iteratable objects 
print(bset) # TypeError

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved