radiansdict.update(dict2)
描述
Python 字典 update() 函数把字典dict2的键/值对更新到dict里。
语法
update()方法语法:
dict.update(dict2)
w.3.x.u.e.com提供本在线速查手册,请勿盗用!
参数
- dict2 -- 添加到指定字典dict里的字典。
返回值
该方法没有任何返回值。
实例
以下实例展示了 update()函数的使用方法:
#!/usr/bin/python3 dict = {'Name': 'W3xue', 'Age': 7} dict2 = {'Sex': 'female' } dict.update(dict2) print ("更新字典 dict : ", dict)
w.3.x.u.e.com提供本在线速查手册,请勿盗用!
以上实例输出结果为:
更新字典 dict : {'Sex': 'female', 'Age': 7, 'Name': 'W3xue'}
注:在3.8.10版本中,输出结果为: 更新字典 dict : {‘Name‘: ‘W3xue‘, ‘Age‘: 7, ‘Sex‘: ‘female‘} 即update()函数在原字典尾部追加键值对,不影响原有键值次序。(感谢匿名网友于2021/10/4 8:40:29指出)
w.3.x.u.e.com提供本在线速查手册,请勿盗用!