2024-04-26 17:39:14 发布
网友
以下是我的Python 3代码:
from time import sleep s='what is your name' for x in s: print(x,end='') sleep(1)
我所期望的是,每封信都会在延迟一秒钟后一封接一封地打印出来。但是当我运行这个程序时,需要花费len(s)秒的时间,然后打印s的值。 谁能向我解释一下到底发生了什么事
len(s)
s
对print函数使用flush参数:
print
flush
print(x, end='', flush=True)
从docs:
Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.
对
print
函数使用flush
参数:从docs:
相关问题 更多 >
编程相关推荐