- sleep() is a python function predefined in 'math' library, which are used to pause the current execution of the program.
- by pausing the current execution, we give a chance to some other process to execute for some time.
Syntax-
time.sleep(seconds)
-Here we pass a number as a argument and unit of number is in seconds.
Example-
sleep(10) pause the current execution for 10 seconds
sleep(5) pause the current execution for 5 seconds
sleep(1) pause the current execution for 1 seconds
program-
import time
print("Start at",time.ctime())
#pause execution for 10 seconds
time.sleep(10)
print("After 10 second",time.ctime())
#pause execution for 20 seconds
time.sleep(20)
print("After 20 second",time.ctime())
#pause execution for 5 seconds
time.sleep(5)
print("After 5 second",time.ctime())
Start at Fri May 3 06:55:37 2019
After 10 second Fri May 3 06:55:47 2019
After 20 second Fri May 3 06:56:07 2019
After 5 second Fri May 3 06:56:12 2019