小编典典

如何在Python中进行时间延迟?

python

如何在Python中进行时间延迟?


阅读 1481

收藏
2020-02-10

共2个答案

小编典典

你可以sleep()在time模块中使用该功能。对于亚秒级分辨率,它可以采用float参数。

from time import sleep
sleep(0.1) # Time in seconds
2020-02-10
小编典典

import time
time.sleep(5)   # Delays for 5 seconds. You can also use a float value.

这是另一个示例,其中某件事大约每分钟运行一次:

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