在Python中操作字典之update()方法的使用
作者:goldensun 时间:2023-01-16 09:55:53
update()方法添加键 - 值对到字典dict2。此函数不返回任何值。
语法
以下是update()方法的语法:
dict.update(dict2)
参数
dict2 -- 这是被添加dict到的词典
返回值
此方法不返回任何值
例子
下面的例子显示了update()方法的使用
#!/usr/bin/python
dict = {'Name': 'Zara', 'Age': 7}
dict2 = {'Sex': 'female' }
dict.update(dict2)
print "Value : %s" % dict
当我们运行上面的程序,它会产生以下结果:
Value : {'Age': 7, 'Name': 'Zara', 'Sex': 'female'}
标签:Python,字典
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python实现BP神经网络回归预测模型
2023-01-21 17:53:44
![](https://img.aspxhome.com/file/2023/2/98322_0s.png)
python下setuptools的安装详解及No module named setuptools的解决方法
2022-12-21 00:56:46
python实现在图片上画特定大小角度矩形框
2023-03-16 22:03:14
![](https://img.aspxhome.com/file/2023/6/65036_0s.jpg)
PHP 对象继承原理与简单用法示例
2023-11-21 21:57:32
python字典key不能是可以是啥类型
2022-12-28 20:54:04
django自带的权限管理Permission用法说明
2023-07-25 04:18:06
![](https://img.aspxhome.com/file/2023/1/61491_0s.jpg)
Oracle对两个数据表交集的查询
2010-07-26 12:51:00
python beautiful soup库入门安装教程
2023-03-04 06:24:27
![](https://img.aspxhome.com/file/2023/2/92092_0s.png)
如何使用scrapy中的ItemLoader提取数据
2021-01-10 07:02:06
![](https://img.aspxhome.com/file/2023/4/123484_0s.png)
用Python实现网易云音乐的数据进行数据清洗和可视化分析
2023-07-03 18:53:00
![](https://img.aspxhome.com/file/2023/8/85188_0s.png)
如何测试字符串的长度?
2009-11-11 20:02:00
python中random.randint和random.randrange的区别详解
2021-03-11 00:24:15
![](https://img.aspxhome.com/file/2023/2/109862_0s.png)
Numpy中的数组搜索中np.where方法详细介绍
2022-08-31 22:09:40
phpstudy apache开启ssi使用详解
2023-05-25 08:04:44
语义化提高页面质量
2007-10-07 11:56:00
python编写接口测试文档(以豆瓣搜索为例)
2023-09-21 17:39:49
![](https://img.aspxhome.com/file/2023/2/62282_0s.png)
Python unittest discover批量执行代码实例
2023-08-14 14:05:37
Oracle9i的全文检索技术开发者网络Oracle
2010-07-18 13:22:00
Access数据库操作中出现的怪现象
2008-04-24 14:22:00
python函数的两种嵌套方法使用
2022-01-14 08:06:58