在Python中的for循环中,额外参数意味着什么?

Tru*_*an1 6 python for-loop

我遇到了一个对我不熟悉的for循环.method这个for循环意味着什么?

for method, config in self.myList.items():

NDe*_*vox 7

items()是有关python使用的方法dictionaries来返回一个iterable保持tuples用于每个字典的的keys和它们对应的value.

在Python中,您可以使用您显示的方法解压缩liststuples转换为变量.

例如:

item1, item2 = [1,2]
# now we have item1 = 1, item2 = 2
Run Code Online (Sandbox Code Playgroud)

因此,假设self.myList是一个dict,method并且config将涉及到keyvalue在每个tuple分别用于该次迭代.

如果self.myList不是a dict,我会认为它要么继承,dict要么它的items()方法类似(你会更清楚).