sleep() function in python by R4R Team

- 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.



-Here we pass a number as a argument and unit of number is in seconds.


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


import time

print("Start at",time.ctime())

#pause execution for 10 seconds
print("After 10 second",time.ctime())

#pause execution for 20 seconds
print("After 20 second",time.ctime())

#pause execution for 5 seconds
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

-In this program, we start execution at some time shown in above output, then we use sleep(10) which pause this current program for 10 seconds.

Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!