How to Add Delay in Python

To add delay in Python, you can use the time.sleep() function from the time library.

The following example shows how to add delay in Python.

Using time.sleep() Function

We can use the time.sleep() function to add a delay in Python.

Suppose we want to add a delay of 5 seconds before printing “Hello, World!”:

# Import time module
import time

# Add delay
time.sleep(5)

# Print Hello world
print("Hello, World!")

When we run this program, it will add a delay of 5 seconds before printing “Hello, World!”.