Python day4知识回顾
2024-08-31 12:55:20
# -*- coding: utf_8 _*_
# Author:Vi
#字典是无序的 info = {
'student001':"DIO",
'student002':"JOJO",
'student003':"Pucci",
} '''
#print(info['student003'])
info['student001'] = "屌"#对已有字典进行修改
info['student004'] = "Zepple"#添加新的
#del info['student001']#删除
#info.pop("student001")#也是删除
print(info)
info.popitem()#随即删一个
print(info)
print(info.get('student003'))#判断字典内有没有这个东西
print('student002' in info)#判断是否在内返回真假值
'''
infob = {
'student001':"Dongwei",
1:3,
2:4
}
info.update(infob)#更新字典,有的话就代替,没有就创建
c = dict.fromkeys([6,7,8],"DIO")#初始化一个新的字典,key已经写好了,后面可以赋值;
print(info.items())#将字典改成列表
print(c)
for i in info:
print(i,info[i])#字典循环方式
#多级字典嵌套及操作
game_cataloge = {
'Chinese':{
"www.didi.com":["Many resources","Good qualities"],
"www.womiao.com":["Beautiful Web","Many things"],
},
'Japan':{
"www.pixiv.com":["Splendid pictures and comic","VPN NEED"],
"www.asanews.com":["Japan local news","vpn must"],
}
}
game_cataloge['Chinese']["www.di" \
"di.com"][1] = "Bad qualities"#修改多级字典
game_cataloge.setdefault("Japan1",{"www.keroro.com"})#能取到值就返回,取不到就创建一个新的
print(game_cataloge)
#print(game_cataloge.keys())#打印keys
最新文章
- Git版本控制管理学习笔记1-介绍
- Android 笔记 day3
- Android ProgressBar分析及自定义ProgressBar
- [原创]C#应用WindowsApi实现查找(FindWindowEx)文本框(TextBox、TextEdit)。
- UIkit框架之UIcollection
- 【nodejs】使用Node.js实现REST Client调用REST API
- .net版ckeditor配置水印功能(转)
- MongoDB分布式
- KVO等具体实现步骤以及注意事项
- SpringSecurity的配置分析
- 关键字new与malloc函数
- cartographer 安装问题
- windows下网络丢包模拟软件(Network Emulator for Windows Toolkit)
- Intel 面试(就不该报外企,英语是硬伤)
- 练习vue(用户管理)1
- 搭建 Digital Ocean 服务器
- js getAttribute getAttributeNode
- 阿里云云主机添加swap分区与swap性能优化
- css中的block与none
- 使用Mondrian Virtual OLAP Cube 实现星座模型并在saiku展现分析