Google Colab 不打印 for 循环输出

Neo*_*Neo 2 printing google-colaboratory

我正在使用 Google Colab,发现它不打印循环输出。请查看以下屏幕截图的输出,单元格运行但没有打印输出。有人遇到这个问题吗,如何解决?谢谢。

for i in range(5):
    print('{0} out of {1} numbers have been printed'.format(i+1,5),end='\r')

Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Mif*_*zak 6

我不知道为什么。但是,如果您希望第一个打印被下一个打印替换,您可以通过\r在开头添加并让结尾为空来尝试此代码。

for i in range(5):
  print('\r {0} out of {1} numbers have been printed'.format(i+1,5),end='')
Run Code Online (Sandbox Code Playgroud)

你会得到结果

5 out of 5 numbers have been printed
Run Code Online (Sandbox Code Playgroud)