Python3 字典 update() 方法


 Python3 字典


描述

Python 字典 update() 函数把字典dict2的键/值对更新到dict里。

语法

update()方法语法:

dict.update(dict2)

参数

  • dict2 -- 添加到指定字典dict里的字典。

返回值

该方法没有任何返回值。

实例

以下实例展示了 update()函数的使用方法:

#!/usr/bin/python3 dict = {'Name': 'Runoob', 'Age': 7} dict2 = {'Sex': 'female' } dict.update(dict2) print ("更新字典 dict : ", dict)

以上实例输出结果为:

更新字典 dict : {'Sex': 'female', 'Age': 7, 'Name': 'Runoob'}

 Python3 字典

 声明:原文来自菜鸟教程http://www.runoob.com/python3/

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM