#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的更多相关文章

随机推荐

  1. Jmeter中JDBC Request和BeanShell PostProcessor的结合使用(SQL模糊查询)

    [前言] 今天记录一下Jmeter中JDBC Request和BeanShell PostProcessor的结合使用的方法(SQL模糊查询) [步骤] 1.下载对应数据库的驱动包到jmeter安装目 ...

  2. java 定位问题方法 (jdb 和 jstack)

    使用java 做开发,大部分的朋友都是利用DIE 来做debug 工作,因为这样可视化效果好. 但是在真实的工作中,很多使用遇到问题,手头或者环境是不允许你利用DIE 来对源码做debug 工作,开发 ...

  3. myclipse运行web的一些问题

    一.修改项目访问路径 项目右键>properties(属性)>输入web搜索>双击web>修改Web-Content root内容即可 二. myeclipse中web项目不自 ...

  4. 问题 Can't load AMD 64-bit .dll on a IA 32-bit platform

    问题简要描述: java.lang.UnsatisfiedLinkError: F:\Tools\tomcat6045\tomcat6.0.45_x64\apache-tomcat-6.0.45\bi ...

  5. Technical support website

    Technical support:Please leave a message if you have any questions or suggestions. email: swvrwafet@ ...

  6. Oracle 11g安装报错Environment variable: "PATH"

    Environment variable: "PATH" - This test checks whether the length of the environment vari ...

  7. 016 3Sum Closest 最接近的三数之和

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  8. 迅雷笔试题 (JAVA多线程)启动三个线程,分别打印A B C,现在写一个程序 循环打印ABCABCABC

    题目:http://wenku.baidu.com/view/d66187aad1f34693daef3e8a.html 启动三个线程,分别打印A B C,现在写一个程序 循环打印ABCABCABC. ...

  9. 二进制读取 jdbc

    package com.itheima.clob.test; import java.io.FileInputStream; import java.io.FileOutputStream; impo ...

  10. 【开源我写的富文本】打造全网最劲富文本技术选型之经典OOP仍是魅力硬核。

    套路--先贴图 demo :  http://www.vvui.net/editor/index.html gitee : https://gitee.com/kevin-huang/Bui-Edit ...