![](/img/trans.png)
[英]I got different results for a while loop and for loop in python (check the codes)
[英]Undertanding the disimilarities between 2 similar codes with different results in python while loop
在第 13 行增加x
,然后在第 14 行打印x+1
。
因此,您在循環的每次迭代中得到兩個打印,以及 X=6 的 output (據我了解,這里有什么困擾您)。
您可以更改代碼以在 while 循環結束后進行額外打印:
x = 0
while x < 5:
print("Not yet there, X=" + str(x))
x += 1
print("X=" + str(x))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.