Python3 字典 update() 方法

Python3 字典 Python3 字典


描述

Python 字典 update() 函數把字典參數 dict2 的 key/value(鍵/值) 對更新到字典 dict 裏。

語法

update() 方法語法:

dict.update(dict2)

參數

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

返回值

該方法沒有任何返回值。

實例

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

實例(Python 2.0+)

#!/usr/bin/python3 dict = {'Name': 'zaixian', 'Age': 7} dict2 = {'Sex': 'female' } dict.update(dict2) print ("更新字典 dict : ", dict)

以上實例輸出結果為:

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

Python3 字典 Python3 字典