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.

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())


output-

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:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in 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!