- items() 返回字典的键值对:
car = {
"brand": "Porsche",
"model": "911",
"year": 1963
}
x = car.items()
print(x)

- 同时遍历键和键值
def f(**args):
for i,j in args.items():
print(i,j)
f(a = 'bab')

- 遍历字典
[python按顺序遍历字典中的所有键_python中怎么遍历字典]
(https://blog.csdn.net/weixin_39922361/article/details/110538688)
num = 1
box_dict = {'q1':None,'q2':None,'q3':None}
for i in box_dict.keys():
locat = ((num+1)*(df_max.shape[0]+1))/4
box_dict[i] = locat
num += 1
box_dict

Python字典操作:items()与遍历技巧
本文介绍了Python字典的items()方法,它用于返回字典的键值对。示例中展示了如何使用items()遍历字典,并通过函数参数演示了同时遍历键和值的方法。此外,还提供了按顺序遍历字典键的实例,强调了在字典遍历中的应用。

被折叠的 条评论
为什么被折叠?



