gpt4 book ai didi

python - 如何在 python 3 中从 for 循环内部增加迭代器?

转载 作者:太空狗 更新时间:2023-10-29 17:42:45 25 4
gpt4 key购买 nike

for i in range (0, 81):
output = send command
while True:
last_byte = last_byte - offset
if last_byte > offset:
output = send command
i+
else:
output = send command
i+
break

我想在每次执行发送命令时增加迭代器。现在它只在执行 for 循环时增加 1。请指教

for i in range(0,10):
print(i)
i +=2
print("increased i", i)

我运行这段代码,结果是从 0 到 9。我原以为它会将迭代器增加 2。

最佳答案

将迭代器的副本保存为命名对象。然后,如果您愿意,可以跳过。

>>> myiter = iter(range(0, 10))
>>> for i in myiter:
print(i)
next(myiter, None)
...
0
2
4
6
8

关于python - 如何在 python 3 中从 for 循环内部增加迭代器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32280091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com