How to Put a Time Delay in Python?


There are multiple ways to put a time delay in Python. Some commonly used methods are:

  1. Using the time module:
import time

# delay for 2 seconds
  1. Using the datetime module:
import datetime

# delay for 2 seconds
start_time =
while ( - start_time).seconds < 2:
  1. Using the timeit module:
import timeit

# delay for 2 seconds

Note: It is important to note that the accuracy of the delay may vary depending on the system load and other factors.

Latest Questions

python How to Fix ""zsh: command not found: python" Error on MacOS X? python How to Fix "xlrd.biffh.XLRDError: Excel xlsx file; not supported" Error in Pandas? python How to Remove All Whitespace From a Python String?