- 1
- 0
- 约1.43千字
- 约 2页
- 2023-10-28 发布于山东
- 举报
字典
列表是有序的对象集合,字典是无序的对象集合【键必须是唯一的,但值则不必;值可以取任何数据类型,但键必须是不可变的】无序
dict2={1:1,2:2,(3):(3)}
print dict2 #得 {3: 3, 1: 1, 2: 2} 元组类型发生了改变
dict2={1:1,2:2,(3,2):(3,2)}
print dict2 #{1: 1, (3, 2): (3, 2), 2: 2} 元组未发生改变
dict2={1:1,2:2,(3,2):(3,2),4:[5],5:{66:66},(3):{77,88}} #键必须是不可变的,值可以是任何类型:依次为数字,字符,元组,列表,字典,set集合
print dict2 #得 {1: 1, (3, 2): (3, 2), 3: set([77, 88]), 4: [5], 2: 2, 5: {66: 66}}
info = {
stu1101: 安徽,
stu1102: 北京,
stu1103: 河南,
}
# 增删查改
info[stu1104] = 浙江 #增
info[stu1101] = 中国 #改
info.pop(stu1104) #删
# del info[stu1104] # 删
print(info.get(stu1106)) # 查询,
原创力文档

文档评论(0)