Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a time delay in Python? [duplicate]

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

like image 871
user46646 Avatar asked Feb 04 '09 07:02

user46646


People also ask

How do you set a time delay in Python?

The standard way to add a time delay in Python is by calling the sleep() function from the time module. It works by suspending the execution of the calling thread for the specified number of seconds, which may be a floating-point value.

Can you make a delay in Python?

Adding a Python sleep() Call With time. The time module has a function sleep() that you can use to suspend execution of the calling thread for however many seconds you specify. If you run this code in your console, then you should experience a delay before you can enter a new statement in the REPL.

How do I print a delay in Python?

Make your time delay specific by passing a floating point number to sleep() . from time import sleep print("Prints immediately.") sleep(0.50) print("Prints after a slight delay.")


1 Answers

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). 
like image 146
Evan Fosmark Avatar answered Oct 03 '22 03:10

Evan Fosmark