Latest web development tutorials

Python3 字典update() 方法

Python3 字典 Python3字典


描述

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

語法

update()方法語法:

dict.update(dict2)

參數

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

返回值

該方法沒有任何返回值。

實例

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

#!/usr/bin/python3

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

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

以上實例輸出結果為:

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

Python3 字典 Python3字典