python学习笔记 - for循环: 遍历字典, 分别打印key, value, key:value

#遍历字典, 分别打印key, value, key:value
emp = {'name':'Tom', 'age':20,  'salary' : 8800.00}

for k in emp.keys():
                print('key = {}'.format(k))
                
for v in emp.values():
                print('values = {}'.format(v))
                
for v,k in emp.items():
                print('{v}:{k}'.format(v = v, k = k))

 打印结果:
key = name
key = age
key = salary

values = Tom
values = 20
values = 8800.0

name:Tom
age:20
salary:8800.0

posted @ 2017-04-19 14:03  C/C++/Python/Java  阅读(43602)  评论(0编辑  收藏  举报