Python遍历字典

dict1 = {'name': 'gzy', 'age': 18, 'gender': '男'}

for key in dict1.keys():
    print(key)

for value in dict1.values():
    print(value)

for (key,value) in dict1.items():
    print(f'{key} : {value}')

for item in dict1.items():
    print(item)

posted @ 2021-03-08 18:04  code-G  阅读(81)  评论(0编辑  收藏  举报