我是 Python 新手,但很難理解以下 While 循環(huán)代碼,因?yàn)樗男袨榉浅2煌?。我知道這段代碼有效,但我不知道它是如何工作的。頂級(jí) Python 專家也不知道。x = 1while x < 10: print x x = x + 1 ## How does this VAR manipulate Print as the VAR comes late in the code?我不知道這是否與控制流或全局變量有關(guān)。請(qǐng)幫助我更深入地了解。
3 回答

慕俠2389804
TA貢獻(xiàn)1719條經(jīng)驗(yàn) 獲得超6個(gè)贊
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
讓我再告訴你一件事,你這里沒有任何全局變量的情況。
如果您在理解它是全局聲明還是本地聲明時(shí)遇到困難,我建議您點(diǎn)擊此鏈接
添加回答
舉報(bào)
0/150
提交
取消