我是 Python 新手,但很难理解以下 While 循环代码,因为它的行为非常不同。我知道这段代码有效,但我不知道它是如何工作的。顶级 Python 专家也不知道。x = 1while x < 10: print x x = x + 1 ## How does this VAR manipulate Print as the VAR comes late in the code?我不知道这是否与控制流或全局变量有关。请帮助我更深入地了解。
3 回答

慕侠2389804
TA贡献1719条经验 获得超6个赞
x = 1 #Declares the variable
while x < 10: #checks whether the value of x is less than 10 every time the loop runs
print x #prints value of x for the each iterations(1 for first iteration, 2 for second and so on)
x = x + 1 #this is the update part
让我再告诉你一件事,你这里没有任何全局变量的情况。
如果您在理解它是全局声明还是本地声明时遇到困难,我建议您点击此链接
添加回答
举报
0/150
提交
取消