我遇到了一个对我来说不常见的 for 循环。 method
在此 for 循环中意味着什么?
方法,配置在self.myList.items():
最佳答案
items()
是一种在 python dictionaries
上使用的方法,用于返回一个 iterable
为每个元素保存 tuples
字典的键
及其对应的值
。
在 Python 中,您可以使用您展示的方法将 lists
和 tuples
解包到变量中。
例如:
item1, item2 = [1,2]
# now we have item1 = 1, item2 = 2
因此,假设 self.myList
是一个 dict
,method
和 config
将与 相关>key
和 value
分别在该次迭代的每个 tuple
中。
如果 self.myList
不是 dict
,我会假设它继承自 dict
或者它是 items()
方法类似(你会知道的更好)。
关于python - 额外参数在 Python 中的这个 for 循环中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29655449/