17 字典公共功能
1、len
info = {"name":'刘伟达','age':18,'gender':'男','hobby':'同桌'}
print(len(info))
2、索引
info = {"name":'刘伟达','age':18,'gender':'男','hobby':'同桌'}
info['name']
info['age']
3、切片【无】
4、步长【无】
5、for
info = {"name":'刘伟达','age':18,'gender':'男','hobby':'同桌'}
for item in info.keys():
print(item)
for item in info.values():
print(item)
for k,v in info.items():
print(k,v)
6、修改
(存在修改/不存在增加)
# 改值
info = {"name":'刘伟达','age':18,'gender':'男','hobby':'同桌'}
info['age'] = 19
print(info)
# 改键
# 删除后再增加
del info['hobby']
info['xxxxx'] = 'x1'
7、删除
info = {"name":'刘伟达','age':18,'gender':'男','hobby':'同桌'}
del info['name']
print(info)