问题描述
我给出了下面的代码,它在python中
from time import *
# I dont need to use time every time
print("hi",end="")
sleep(3)
print(".",end="")
sleep(3)
print("." )
我打招呼...但是花了9到10秒钟才打印出任何东西并且中间没有任何缝隙
解决方法
将flush
参数设置为True
可使您的print()
语句及时打印。
from time import sleep
print("hi",end="",flush=True)
sleep(3)
for i in range(3):
print(".",flush=True)
sleep(3)