我正在同一print()命令中打印2/3。但是我想在某些时候使用睡眠。像这样:
print("Hello world!")
time.sleep(1)
print ("I just stopped for 1 sec!!")
time.sleep(1)
print (" But I want to Marge these lines. How?")
对此或类似内容:
print ("Hello world!",time.sleep(1),"I just stopped for 1 sec!!",time.sleep(1)," But I want to Marge these lines. How?")
答案 0 :(得分:1)
更改end
以防止print
添加换行符,并确保flush
语句强制其打印,然后再继续。
import time
print("Hello world!", end=" ", flush=True)
time.sleep(1)
print ("I just stopped for 1 sec!!", end=" ", flush=True)
time.sleep(1)
print ("But I want to Marge these lines. How?")
输出:
Hello world! I just stopped for 1 sec!! But I want to Marge these lines. How?