1.遍历字典的key
dict = {'name':'tom','age':20,'gender':'男'}
for k in dict.keys():
print(k)
执行结果是
2.遍历字典的 valuedict = {'name':'tom','age':20,'gender':'男'}
for v in dict.values():
print(v)
执行结果是
3.遍历字典的元素
dict = {'name':'tom','age':20,'gender':'男'}
for items in dict.items():
print(items)
执行结果是
4.遍历字典的键值对dict = {'name':'tom','age':20,'gender':'男'}
for k,v in dict.items():
print(k,v)
执行结果是
标签:遍历,20,name,Python,gender,dict,字典 From: https://blog.csdn.net/m0_60444702/article/details/143898207