下面是我遇到问题的python代码:
for i in range (0,10):
if i==5:
i+=3
print i
Run Code Online (Sandbox Code Playgroud)
我期望输出为:
0
1
2
3
4
8
9
Run Code Online (Sandbox Code Playgroud)
然而翻译吐出:
0
1
2
3
4
8
6
7
8
9
Run Code Online (Sandbox Code Playgroud)
我知道for循环为C中的变量创建了一个新的作用域,但不知道python.任何人都可以解释为什么python i中的for循环中没有变化的值,并且为了获得预期的输出有什么补救措施.