Python - 更改字典項
更改值
您可以透過引用其鍵名來更改特定項的值
示例
將“year”更改為 2018
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["year"] = 2018
自己動手試一試 »
更新字典
update()
方法將使用給定引數中的項更新字典。
該引數必須是一個字典,或一個具有鍵值對的可迭代物件。
示例
使用 update()
方法更新汽車的“year”
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.update({"year": 2020})
自己動手試一試 »