代码点读机 / Python / update

update Python · 通用方法

把另一个集合或字典的内容合并进来,相同键会覆盖。

怎么用

字典.update(字典) 或 集合.update(可迭代对象)

小例子

d = {'a': 1}
d.update({'b': 2})
print(d)

运行结果

{'a': 1, 'b': 2}

官方文档:https://docs.python.org/zh-cn/3/library/stdtypes.html

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条