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

# 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'}

 

posted @ 2017-08-08 16:53  liuzhipenglove  阅读(122)  评论(0编辑  收藏  举报