Python3 字典 Python3 字典


描述

Python 字典 update() 函數(shù)把字典dict2的鍵/值對更新到dict里。

語法

update()方法語法:

dict.update(dict2)

參數(shù)

  • dict2 -- 添加到指定字典dict里的字典。

返回值

該方法沒有任何返回值。

實例

以下實例展示了 update()函數(shù)的使用方法:

#!/usr/bin/python3

dict = {'Name': 'W3CSchool', 'Age': 7}
dict2 = {'Sex': 'female' }

dict.update(dict2)
print ("更新字典 dict : ", dict)

以上實例輸出結(jié)果為:

更新字典 dict :  {'Name': 'W3CSchool', 'Age': 7, 'Sex': 'female'}


Python3 字典 Python3 字典