首页 › 参考手册 › 字典方法 › dict.update()

Python dict.update() 方法

描述

用另一个字典或键值对更新当前字典,已存在的键会被覆盖。

语法

dict.update([other], **kwargs)

参数

参数说明
other字典或键值对

返回值

None

实例

d = {"a": 1, "b": 2}
d.update({"b": 20, "c": 3})
d.update(d=4)
print(d)
以上实例输出结果为:
{'a': 1, 'b': 20, 'c': 3, 'd': 4}