How to make Python program to sleep for milliseconds?

For making Python program to sleep for some time, we can use the time.sleep() method. Here the argument takes in seconds. In order to use this method to sleep for milliseconds, you just use a fractional number. For example, to sleep for 400 millisecond use time.sleep(0.4), for 60 milliseconds use time.sleep(0.06) and so on.

import time

print("This is before sleeping.")
time.sleep(0.5)     # Sleep for 500 milliseconds
print("This is after 500 milliseconds.")
time.sleep(0.075)   # Sleep for 75 milliseconds
print("This is after 75 milliseconds.")
make Python program to sleep for milliseconds

Reference


Leave your thoughts...

This site uses Akismet to reduce spam. Learn how your comment data is processed.