Python dictionary update() 方法
搞懂Python dictionary update() 方法的用法
描述
Python 字典 update() 函数把字典参数 dict2 的
key/value(键/值) 对更新到字典 dict 里。
语法
update() 方法语法:
参数
dict2 -- 添加到指定字典dict里的字典。
返回值
该方法没有任何返回值。
实例
以下实例展示了 update()函数的使用方法:
dict = {'Name' : 'Lidihuo' , 'Age' : 2 }
dict2 = {'url' : 'www.lidihuo.com'}
dict.update ( dict2 )
print("更新字典 dict : " , dict)
以上实例输出结果为:
更新字典 dict : {'Name': 'Lidihuo', 'Age': 2, 'url': 'www.lidihuo.com'}