And in its simplest and original form, this is exactly what the for-in statement does; when you write
for name in train:
do something with name
the interpreter will simply fetch train[0]and assign it to name, and then execute the code block. It’ll then
fetch train[1], train[2], and so on, until it gets an IndexError.
相当于
也就是说,在每次迭代开始时,迭代器产生的下一个值被分配给循环变量。你知道吗
从Understanding Python's "for" statement:
或者,我们可以使用^{} 并检查机器代码:
我们设置一个循环,呼叫范围,然后:
16
^{11 (to 30)
它将迭代器的结果推送到堆栈上,然后我们将其
STORE_FAST
作为i
使用。你知道吗当迭代器完成时,
FOR_ITER
“TOS
弹出[迭代器],字节码计数器按增量递增。dis
显示的是30:POP_BLOCK
,结束for循环。你知道吗这与开头描述的过程一致。你知道吗
相关问题 更多 >
编程相关推荐