How can I make a time delay in Python?

user46646 picture user46646 · Feb 4, 2009 · Viewed 3.2M times · Source

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

Answer

Evan Fosmark picture Evan Fosmark · Feb 4, 2009
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).