How can I make a time delay in Python?


Question

I would like to know how to put a time delay in a Python script.

1
2578
6/11/2018 12:05:47 AM

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).
2801
6/14/2018 9:04:58 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon