#代码如下:#字典的items,keys,values等属性使用方法info = { "zhangsan": 20, "lisi": 30, "wangwu": 43, "zhaolv": 36, "lisa": 31}print(info.items()) # 打印info所有的键值对print(info.keys()) # 打印info所有的键print(info.values()) # 打印info所有的值print(info["lisi"]) #打印info的键lisi对应的值print(info["zhaolv"]) #打印info的键zhaolv对应的值info["zhaolv"] = 33 # 修改zhaolv的值为33print(info) #打印字典infodel info["lisi"] # 删除字典里的lisi键值对print(info) #打印字典info
运行结果如下:
dict_items([('zhangsan', 20), ('lisi', 30), ('wangwu', 43), ('zhaolv', 36), ('lisa', 31)])
dict_keys(['zhangsan', 'lisi', 'wangwu', 'zhaolv', 'lisa'])
dict_values([20, 30, 43, 36, 31])
30
36
{'zhangsan': 20, 'lisi': 30, 'wangwu': 43, 'zhaolv': 33, 'lisa': 31}
{'zhangsan': 20, 'wangwu': 43, 'zhaolv': 33, 'lisa': 31}
图片示例如下:
![cb615c3111a35a32537bf15f12da8380.png](https://i-blog.csdnimg.cn/blog_migrate/6c7105cdbba64f42159ec329f9cae808.jpeg)