如何在 Python 中进行时间延迟?
问题描述
我想知道如何在 Python 脚本中设置时间延迟.
I would like to know how to put a time delay in a Python script.
解决方案
import time
time.sleep(5) # Delays for 5 seconds. You can also use a float value.
这是另一个大约每分钟运行一次的示例:
Here is another example where something is run approximately once a minute:
import time
while True:
print("This prints once a minute.")
time.sleep(60) # Delay for 1 minute (60 seconds).
相关文章