Python Time Delay

What is time delay in python?

Waiting for definite interval of time before executing next instruction in python program is called time delay.

Is there a delay function in Python?

There is no exact named delay function in python. However you can use sleep() function to make a delay in python.

How to make time delay in python?

sleep() function

To use time delay, we can use the sleep() function which is available in time module of standard python library.

Example of sleep() function

# Python program to demonstrate use of sleep() function

import time

print("Wait for 2 Seconds")

time.sleep(2) # Time you want to delay for, in seconds (can be float value as well)

print("This message was delayed approx. 2 seconds")

''' Output of above code:-

Wait for 2 Seconds
Learning time delays in python

'''
You can also define a time delay in milliseconds using floating point arguments.
# Python program to demonstrate use of sleep() function

import time

print("Wait for 2.123 Seconds")

time.sleep(2.123)

print("Learning use of sleep() function in milliseconds")

''' Output of above code:-

Wait for 2.123 Seconds
Learning use of sleep() function in milliseconds

'''

How do I make python wait?

If you want to to make your Python program wait and don't want to use time.sleep() then you can consider using implicit wait method.
driver.implicitly_wait(5)
The third method is when you have to wait until a particular action is completed or until an element is found:
self.wait.until(EC.presence_of_element_located((By.ID, 'username'))

PAUSE Variable in PyautoGUI library

If you are using pyautogui library then you can use the PAUSE variable to delay time. For example, after setting pyautogui.PAUSE = 2.5, every PyAutoGUI function call will wait two and a half seconds after performing its action. There will be no effect on Non-PyAutoGUI instructions, they will execute normally without any pause.
import pyautogui as py

# just the pause at once it will remain effective throughout the program
py.PAUSE = 2.5