#1 遍历字典的key
info = {"name":"Tom","sex":"male","age":27}
for k in info.keys():
print(k)
#2 遍历字典的value
info = {"name":"Tom","sex":"male","age":27}
for k in info.keys():
print(info[k])
#2 遍历字典的value
info = {"name":"Tom","sex":"male","age":27}
for v in info.values():
print(v)
#3 遍历字典的元素 type(items) 是元组形式的 <class 'tuple'>
info = {"name":"Tom","sex":"male","age":27}
for items in info.items():
print(items)
#4 遍历字典的键值对
info = {"name":"Tom","sex":"male","age":27}
for key,value in info.items() :
print(f'{key} = {value}')
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/qq_38689263/article/details/120398543
内容来源于网络,如有侵权,请联系作者删除!