变量={key1:value1,key2:value2,key3:value3}
key不能重复,重复后面覆盖前面的
不能使用下标,索引为key
key和value可以是任何数据类型 (key不能是字典)
dirc1={'a':1,'b':2,'c':3}
print(dirc1)
print(type(dirc1))
dirc1={'a':1,'b':2,'c':3}
print(dirc1)
print(type(dirc1))
print(f"a的数字是{dirc1['a']}")
dirc1={'a': {'语文':98,'数学':93,'英语':92},
'b':{'语文':93,'数学':91,'英语':98},
'c':{'语文':95,'数学':91,'英语':90}}
print(dirc1)
print(type(dirc1))
print(f"a的语文成绩是:{dirc1['a']['语文']}"
f"a的数学成绩是:{dirc1['a']['数学']}"
f"a的英语成绩是:{dirc1['a']['英语']}")
若key有,则更新key对应的value
dirc1={'语文':98,'数学':93,'英语':92}
print(dirc1)
print(type(dirc1))
dirc1['语文']=100
print(dirc1)
若key没有,则新加key后 增加对应的value
dirc1={'语文':98,'数学':93,'英语':92}
print(dirc1)
print(type(dirc1))
dirc1['化学']=100
print(dirc1)
dirc1={'语文':98,'数学':93,'英语':92,'化学':100}
print(dirc1)
print(type(dirc1))
score=dirc1.pop('化学')
print(dirc1)
print(score)
dirc1={'语文':98,'数学':93,'英语':92,'化学':100}
print(dirc1)
print(type(dirc1))
dirc1.clear()
print(dirc1)
dirc1={'语文':98,'数学':93,'英语':92,'化学':100}
print(dirc1)
print(type(dirc1))
keys=dirc1.keys()
print(keys)
dirc1={'语文':98,'数学':93,'英语':92,'化学':100}
print(dirc1)
print(type(dirc1))
keys=dirc1.keys()
print(keys)
for x in keys:
print(x)
dirc1={'语文':98,'数学':93,'英语':92,'化学':100}
print(dirc1)
print(type(dirc1))
keys=dirc1.keys()
print(keys)
for x in dirc1:
print(x)
dirc1={'语文':98,'数学':93,'英语':92,'化学':100}
print(dirc1)
print(type(dirc1))
num=len(dirc1)
print(num)