博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 示例_带有示例的Python字典update()方法
阅读量:2535 次
发布时间:2019-05-11

本文共 1424 字,大约阅读时间需要 4 分钟。

python 示例

字典update()方法 (Dictionary update() Method)

update() method is used to update the dictionary by inserting new items to the dictionary.

update()方法用于通过将新项目插入字典来更新字典。

Syntax:

句法:

dictionary_name.setdefault(iterable)

Parameter(s):

参数:

  • iterable – It represents an iterbale object or a dictionary to be inserted in the dictionary.

    可迭代 –表示要在字典中插入的iterbale对象或字典。

Return value:

返回值:

It returning nothing.

它什么也没返回。

Example:

例:

# Python Dictionary update() Method with Example# dictionary declarationstudent = {
"roll_no": 101, "name": "Shivang", "course": "B.Tech", "perc" : 98.5}# printing dictionaryprint("data of student dictionary...")print(student)# inserting an itemstudent.update({
'city' : 'Indore'})# printing dictionary after update()print("data of student dictionary after update()...")print(student)# inserting multiple itemsstudent.update({
'city' : 'Indore', 'address' : 'Tech park'})# printing dictionary after update()print("data of student dictionary after update()...")print(student)

Output

输出量

data of student dictionary...{'roll_no': 101, 'name': 'Shivang', 'course': 'B.Tech', 'perc': 98.5}data of student dictionary after update()...{'roll_no': 101, 'name': 'Shivang', 'course': 'B.Tech', 'perc': 98.5, 'city': 'Indore'}data of student dictionary after update()...{'roll_no': 101, 'name': 'Shivang', 'course': 'B.Tech', 'perc': 98.5, 'city': 'Indore', 'address': 'Tech park'}

翻译自:

python 示例

转载地址:http://bnxzd.baihongyu.com/

你可能感兴趣的文章
java基础 第十一章(多态、抽象类、接口、包装类、String)
查看>>
Hadoop 服务器配置的副本数量 管不了客户端
查看>>
欧建新之死
查看>>
自定义滚动条
查看>>
APP开发手记01(app与web的困惑)
查看>>
笛卡尔遗传规划Cartesian Genetic Programming (CGP)简单理解(1)
查看>>
mysql 日期时间运算函数(转)
查看>>
初识前端作业1
查看>>
ffmpeg格式转换命令
查看>>
万方数据知识平台 TFHpple +Xpath解析
查看>>
Hive实现oracle的Minus函数
查看>>
秒杀多线程第四篇 一个经典的多线程同步问题
查看>>
RocketMQ配置
查看>>
vs code调试console程序报错--preLaunchTask“build”
查看>>
蚂蚁金服井贤栋:用技术联手金融机构,形成服务小微的生态合力
查看>>
端口号大全
查看>>
机器学习基石笔记2——在何时可以使用机器学习(2)
查看>>
POJ 3740 Easy Finding (DLX模板)
查看>>
MySQL 处理重复数据
查看>>
关于typedef的用法总结(转)
查看>>