如何在一行中一次一个字地打印一个字符串,并且所有字符串都可见。 - Python

How to print a string one word at a time, on one line with all of the string visible. - Python

我想让这个词:'error' 重复多次。这本身就是一项简单的任务,但我不知道如何以我选择的速度一次打印它们。我知道我的问题已被部分解决,但我不希望字符串的前一个词消失。

 print('Error! ' *20)

我想要的输出是Error!错误! (每个单独发布,而不是一次全部发布。)

我怎样才能做到 python 不会同时释放所有字符串?也很高兴知道我是否可以按列打印,但仍然沿宽度打印。

import time
for _ in range(20):
    print('Error!', end=' ', flush=True) # flush courtesy inspectorG4dget to disable buffering
    time.sleep(0.2)

这将在同一行上每 200 毫秒打印 'Error!'(...20 次)。将 for 更改为 while 以更好地控制停止条件。

这将打印 Error! 20 次(在 20 lines/rows 上),持续时间为 20 秒

import time

for _ in range(20):
    print("Error!")
    time.sleep(1)  # change 1 to whatever number you want, to control the amount of time before "Error!" is printed again

这将在 20 秒的持续时间内在同一行(20 列)上打印 "Error!" 20 次:

import time

for _ in range(20):
    print("Error!", end='', flush=True)
    time.sleep(1)  # change 1 to whatever number you want, to control the amount of time before "Error!" is printed again
import time
for i in range(20):
    print ("Error!")
    time.sleep(60) #pause for one minute

您可以使用 for 循环来选择要打印的次数,并从时间库中 sleep() 进行暂停。