字典

d = {
'name':'jake',
'age': 9,
'grade':5,
}
print(d.get('name')) # get 读取字典K对应值的方式
print(d.keys()) # 读取所有K
print(d.values()) # 读取所有的Value
print(d.items()) # 读取以元组的形式返回值
c = d.pop('name') #去掉name
print(c)
print(d)

#字典的更新
c = {
1:1,
2:2
}
c[3]=3
c[4]=4
print(c)

d= {
5:5,
6:6
}
c.update(d)
print(c)

jake
dict_keys(['name', 'age', 'grade'])
dict_values(['jake', 9, 5])
dict_items([('name', 'jake'), ('age', 9), ('grade', 5)])
jake
{'age': 9, 'grade': 5}
{1: 1, 2: 2, 3: 3, 4: 4}
{1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6}
posted @ 2020-08-11 21:20  KK-KING  阅读(86)  评论(0编辑  收藏  举报