为什么不像打印结束论证那样sleep time.sleep工作?
我正在尝试使用time.sleep()在打印语句之间暂停。
import time
def test():
print("something", end="")
time.sleep(1)
print(" and ", end="")
time.sleep(1)
print("something")
当我使用最终参数时,代码会等待它才开始打印。它应该打印,等待,打印,等待和打印(“某物,等待,等等,等等”)。但是,当我使用最终参数时,它会等待并打印“等待某事”。该代码可以按照我想要的方式工作,而无需结束argumets。
I am trying to use time.sleep() to pause in between print statements.
import time
def test():
print("something", end="")
time.sleep(1)
print(" and ", end="")
time.sleep(1)
print("something")
When I use the end argument, the code waits before it starts to print. It should print, wait, print, wait, and print ("something, wait, and, wait, something"). However, when I use the end argument, it waits, and prints "wait something and something". This code works as I wanted it to without the end argumets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的输出设备是缓冲的,只有在输出新线路时才冲洗。将
flush = true
作为附加参数添加到print
将冲洗施加到输出。Your output device is line-buffered and only flushes when a new line is output. Add
flush=True
as an additional parameter toprint
to force a flush to the output.