A tuple (or list) on the left side of a simple assignment (unpacking is not defined for augmented assignment) may contain at most one expression prepended with a single asterisk (which is henceforth called a "starred" expression, while the other expressions in the list are called "mandatory"). This designates a subexpression that will be assigned a list of all items from the iterable being unpacked that are not assigned to any of the mandatory expressions, or an empty list if there are no such items.
是“的缩写”
所以你不应该把逗号看作是语句的分隔,而是值的分隔(例如
life, universe, everything = the_answer
或li = [4, 2]
)它只取决于循环的iteable中的值的数量是的。所以呢
for
关键字后面可以跟任意变量名。你知道吗在本例中,由于
enumerate()
包含iterable的项,它使用了2个变量i, col
。你知道吗有关iterable解包的更多信息,请阅读pep3131https://www.python.org/dev/peps/pep-3132/
相关问题 更多 >
编程相关推荐