Python——字典操作

一、取出字典中所有的key-value

student={'name':'xiaoming','age':11,'school':'tsinghua'}
for key,value in student.items():
    print(key+':'+str(value))

二、取出字典中所有的keys

people={'lifei':'apple','fanming':'peach','gaolan':'banana','hanmeimie':'peach'}
for name in people.keys():
    print(name)

**如果想输出按照顺序需要   sorted(people.keys())

三、取出字典中所有的value

people={'lifei':'apple','fanming':'peach','gaolan':'banana','hanmeimie':'peach'}
for fruit in people.values():
    print(fruit)

 

posted @ 2019-02-26 10:40  澄心元素  阅读(377)  评论(0编辑  收藏  举报