#遍历字典, 分别打印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