python - 额外参数在 Python 中的这个 for 循环中意味着什么?

标签 python for-loop

我遇到了一个对我来说不常见的 for 循环。 method 在此 for 循环中意味着什么?

方法,配置在self.myList.items():

最佳答案

items() 是一种在 python dictionaries 上使用的方法,用于返回一个 iterable 为每个元素保存 tuples字典的及其对应的

在 Python 中,您可以使用您展示的方法将 liststuples 解包到变量中。

例如:

item1, item2 = [1,2]
# now we have item1 = 1, item2 = 2

因此,假设 self.myList 是一个 dictmethodconfig 将与 相关>keyvalue 分别在该次迭代的每个 tuple 中。

如果 self.myList 不是 dict,我会假设它继承自 dict 或者它是 items() 方法类似(你会知道的更好)。

关于python - 额外参数在 Python 中的这个 for 循环中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29655449/

相关文章:

algorithm - 嵌套 for 循环的时间复杂度,内部迭代变量依赖于外部迭代

java - Pig Latin 翻译器——寻找辅音簇。

ios - 数组中的 NSNumber,ios

python - 在编译Python之前升级pip?

python - 更改 qtablewidget 中的颜色(单击)

python - YouTube-dl 和 Ffmpeg

python - 您可以将一个 for 循环嵌套在另一个 for 循环中,并且它们具有相同的循环变量吗?

c# - Unity C# - for 循环 : go from one object to the next one (movement) - gets stuck on first object

python - python 3中的对齐、间距

python - 如何放大子图matplotlib?