我如何制作时间延迟?[重复]

19 浏览
0 Comments

我如何制作时间延迟?[重复]

这个问题已经有解答了:

如何让我的Python程序休眠50毫秒?

我该如何在Python脚本中设置时间间隔?

admin 更改状态以发布 2023年5月23日
0
0 Comments

使用time模块中的sleep()方法。它可以接受浮点数参数来表示子秒分辨率。

from time import sleep
sleep(0.1)  # Time in seconds

0
0 Comments

这会延迟2.5秒:

import time
time.sleep(2.5)


这是另一个例子,在这里某些东西大约每分钟运行一次:

import time
while True:
    print("This prints once a minute.")
    time.sleep(60) # Delay for 1 minute (60 seconds).

0