This post will discuss how to add a time delay in Python.

1. Using time.sleep() function

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.

Download  Run Code

2. Using threading.Event.wait function

Another alternative is to use the Event.wait function in the threading module. Here’s what the code would look like:

Download  Run Code

3. Using threading.Timer class

If you need to delay the execution of a specific function instead of stopping the execution of the whole program, consider using the threading.Timer Python class, as shown below:

Download  Run Code

That’s all about adding a time delay in Python.