简体   繁体   English

我们可以在多行打印中使用 time.sleep 函数吗

[英]Can we use time.sleep function in multinline print

I am making a script that had a multi-line print functions like this我正在制作一个具有多行打印功能的脚本

print """ Example
Example
Example
..
"""

I wanna know is there any way we can add time.sleep() function in multi-line print or get a similar functionality like sleep function I want it to look like this.我想知道有什么方法可以在多行打印中添加 time.sleep() 函数或获得类似的功能,例如 sleep 函数我希望它看起来像这样。

print """ Example
time.sleep(1)
Example
time.sleep(1)
Example
time.sleep(1)
..
"""

But this wont work as python just prints time.sleep and i really don't want single-line print command但这不会工作,因为 python 只是打印 time.sleep,我真的不想要单行打印命令

Sorry if this is a dumb question对不起,如果这是一个愚蠢的问题

I think it would be easier to use a loop:我认为使用循环会更容易:

times = 3
for i in range(0, times):
    print('Example')
    time.sleep(1)

This probably isn't the most efficient way of doing this but it's a way that will work.这可能不是最有效的方法,但这是一种可行的方法。

from time import sleep

print("example")
sleep(1)
print("example")
sleep(1)
print("example")
sleep(1)

Although a loop would work like the previous answer that could be an issue when you have different strings.尽管循环会像之前的答案一样工作,但当您有不同的字符串时,这可能会成为问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM