当前位置:网站首页>Section 15 of Chapter 2: basic operation of dictionary
Section 15 of Chapter 2: basic operation of dictionary
2022-07-21 15:15:00 【Zhongyifeng Digital Technology Co., Ltd】
Python Basic introduction ( A full set of nanny level tutorials )
Chapter two
Section 15 : Basic operation of dictionary
Look up the dictionary
increase
dic = dict()
dic['jay'] = " Jay Chou "
dic[1] = 123
print(dic)
modify
here , It's already in the dictionary jay. At this time, the modification operation is executed
dic['jay'] = " Kunling " # here , It's already in the dictionary jay. At this time, the modification operation is executed
print(dic)
setdefault
Set the default value . If it had existed before tom 了 . setdefault It doesn't work
dic.setdefault("jay", " soup with pepper ") # Set the default value . If it had existed before tom 了 . setdefault It doesn't work
print(dic)
Delete
according to key To delete
dic.pop("jay") # according to key To delete
print(dic)
Inquire about
dic [ ] If key non-existent . The program will report an error . When you are sure of your key No problem , It can be used
get If key non-existent . Program return None. When unsure of your key When . It can be used
print(dic['jay10010']) # If key non-existent . The program will report an error . When you are sure of your key No problem , It can be used
print(dic.get('jay10086')) # If key non-existent . Program return None. When unsure of your key When . It can be used
None Pure is empty , It means nothing
a = None # Pure is empty , It means nothing
print(type(a))
Example :
dic = {
" Zhao si ": " He can crook his mouth ",
" Lennon ": " The old , Old four ...",
" Bigfoot ": " Have sex with this and that ",
" Big head ": " act blindly ....",
}
name = input(" Please enter the name of the people in our village you want to know : ")
val = dic.get(name)
if val is None:
print(" There is no such person in our village ~~~")
else:
print(val)
When you enter, you cannot find , Output none There is no such person in our village .
边栏推荐
- 国债逆回购安全吗 怎么卖出去
- This startup wants to see your Ding Ding! They use AI to detect sexual diseases and ensure data anonymity and encryption. Would you like to
- 乘数科技云管控平台适配阿里云 PolarDB,共促云原生数据库生态繁荣
- 调研报告之——可见光通信与可见光定位
- Is the reverse repurchase of treasury bonds safe? How to sell it
- 【CVA估值训练营】读懂上市公司年报_第二讲
- Hangzhou dynamic environment monitoring system supplier, dynamic environment monitoring equipment
- Web3流量聚合平台Starfish OS,给玩家元宇宙新范式体验
- 【C 练习】求一个数最少需要多少步可变为斐波那契数
- 魑魅魍魎
猜你喜欢
随机推荐
Kingbasees database administrator's Guide -- 15.3 Management synonyms
如何给selenium.chrome写扩展拦截或转发请求
基于可见光通信的移动机器人室内定位及物联网应用
nacos集群搭建
Hutoo - date time tool -dateutil
Web3流量聚合平台Starfish OS,诠释真正商业的“P2E”生态
DevExpress之GridControl按delete键删除所选行项
Internship: several steps to get familiar with the project code
魑魅魍魉
Semantic matching of English keyword text splitting
第二章第六节:字符串的补充和总结
C#单例模式
修改电脑注册表,将VSCode添加至鼠标右键菜单
Spark Sql编译模块-词法、语法分析器Antlr4(一
WinForm版本更新(简易版)
Kingbasees database administrator's Guide -- 15.1 Manage views
Flask 源码剖析(一)请求入口
C#调用存储过程传输表值参数
Kingbasees SQL language reference manual of Jincang database (3.5 format model, 3.6 null value, 3.7 comments)
数据仓库和数据中台的关系