Python provides a handy method called Sleep( ) which is part of time module. sleep python method pauses/suspends the python program for certain amount of specifed time.
Python time.sleep( ) is similar to shell sleep command. It accepts the argument in seconds/milli seconds.
Note: sleep method is part of time module/package in python 2 and python 3, so you need to import the “time” package.
Syntax of Python time.sleep( ):
Following is the syntax for Python sleep( ) method
time.sleep( t )
t – Number of seconds/milliseconds execution to be suspended.
Following example illustrates the exact usage of sleep( ) method.
import time # Print the start time print("StartTime : ", end ="") print(time.ctime()) # using sleep() to pause the code execution time.sleep(5) # Print the end time print("EndTime : ", end ="") print(time.ctime())
StartTime : Wed May 29 16:50:48 2019 EndTime : Wed May 29 16:50:53 2019