python_26_dictionary
#key-value 字典无下标 所以乱序,key值尽量不要取中文
info={
'stu1101':'Liu Guannan',
'stu1102':'Wang Ruipu',
'stu1103':'Sun Yanan',
}
print(info)
#查找
print(info['stu1101'])#精确查找,若没有则会出错,例如print(info['stu1110'])
print(info.get('stu1110'))#安全查找
print(info.get('stu1103'))
#替换
info['stu1101']='刘冠男'
info['stu1104']='刘冠男'
info['stu1105']='Yu Shasha'
#循环
for i in info:
print(i,info[i])#打印key与value
for k,v in info.items():#先把字典转成列表,然后打印列表,和上式循环效果相同,但数据量很大的时候会很慢,所以尽量用上式
print(k,v)
#判断某个数据在不在字典里,在python2中,info.has_key('stu1103')与python3中'stu1103' in info一样,不过3中没有了2中的写法
print('stu1103' in info)
print('stu1110' in info)
#删除
del info["stu1101"]
info.pop('stu1102')
print(info)
info.popitem()#随机删
print(info)
python_26_dictionary的更多相关文章
随机推荐
- Github搭建个人博客
Github的搭建博客真的是非常容易,所需的步骤只有三个:要完成自己的github.io博客网站,总共分三步:开通自己的github.io repo,选择一款Jekyll的主题,编写并发布博客.下面将 ...
- Chapter12
package scalaimport java.awt.event.{ActionEvent, ActionListener}import javax.swing.JButton import sc ...
- C - Watchmen
题目链接:https://vjudge.net/contest/237394#problem/C Watchmen are in a danger and Doctor Manhattan toget ...
- lazy load的一些网址
http://www.gayadesign.com/scripts/queryLoader/ http://www.oschina.net/p/queryloader http://www.cnblo ...
- 搭建Node.js Redis开发环境
创建项目 初始化为node项目 $npm init 安装redis 安装@types/node, @types/redis, typescript 初始化TypeScript 配置ts ...
- JavaFX上手--第1天
1.第一个JavaFX Application JavaFX 使用Java来制作可视化图形,可以做动画和3D效果,JavaFX从JDK中直接使用. package application; impor ...
- C#字符串自增自减算法
本文URL:http://www.cnblogs.com/CUIT-DX037/p/6770535.html 实现字符串自增和自减运算: 1.数字从 0-9 变化: 2.字母从 A-Z.a-z 变化: ...
- kickstart2019 round_C B. Circuit Board
思路: 这题应该不止一种解法,其中的一种可以看作是leetcode85https://www.cnblogs.com/wangyiming/p/11059176.html的加强版: 首先对于每一行,分 ...
- React搭建脚手架
npm install -g create-react-app //安装 create-react-app react-demo // react-demo 项目的名称 cd react- ...
- springMvc 添加定时任务
1.创建定时类 import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stere ...