字典
1、字典的基本操作
(1)字典的定义
fruits={"苹果": 20, "香蕉": 15,"牛油果": 25}
print(fruits) #字典的定义——大括号+键值对
#结果:{"苹果": 20, "香蕉": 15,"牛油果": 25})
(2)列出字典元素的值
print(fruits["牛油果"])
#25
(4) 字典元素的增加、删除
fruits["橘子"] = 18 #字典元素的增加
del fruits["橘子"]
print(fruits) #字典元素的删除
#结果:{"苹果": 20, "香蕉": 15,"牛油果": 25})
(4) 字典的遍历
players={“zhang”:team1,
“wu”:team2,
“xiao”:team3}
for team, name in players.items():
print(name)
print(team) ##for循环+item()方法实现字典的键值对遍历
2、 字典内含列表
3、字典内含字典