[python][oldboy][dict] 遍历字典

若如初见. 提交于 2019-12-17 17:04:08
# coding=utf8

dict_info = {"abc": 1, 1: "liuzhipeng"}
for k, v in dict_info.items():
    print "{key}->{value}".format(key=k, value=v)

print dict_info.keys()
print dict_info.values()
print dict_info.items()

dict_info.update(abc=3,name="liu",)
print dict_info


#输出
C:\Python27\python.exe C:/Users/Administrator/PycharmProjects/oldboy/lesson_3/test.py
1->liuzhipeng
abc->1
[1, 'abc']
['liuzhipeng', 1]
[(1, 'liuzhipeng'), ('abc', 1)]
{1: 'liuzhipeng', 'abc': 3, 'name': 'liu'}

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!