【发布时间】:2020-05-03 20:51:45
【问题描述】:
以下说明了 Python 中的一个示例 while 循环:
count = 0
print('Starting')
while count < 10:
print(count, ' ', end='') # part of the while loop
count += 1 # also part of the while loop
print() # not part of the while loop
print('Done')
运行这个例子的结果是:
Starting
0 1 2 3 4 5 6 7 8 9
Done
如果代码再次循环并且 print() 在第二个循环中重新运行,我不明白为什么 while 循环会在同一行打印。我期待数字以不同的行打印。我对 while 循环的理解搞砸了什么?
【问题讨论】:
-
我正在从一本书中学习 Python,我还没有达到那么远,这是一个解释 while 循环的例子,它让我对 print 函数感到困惑。但蜥蜴比尔帮了大忙。 :)
标签: python python-3.x while-loop printing