Working with Sleep in Python

In the following programs you will learn that how to sleep or delay execution the program in seconds by using sleep() function of 'time' library.

Program Sleeping Time

Program

import time
print("This is First Line")
time.sleep(3) #sleeping time for 3 Second.
print("This is 2nd Line")
time.sleep(3)
print("This is 3rd Line")
time.sleep(3)
Output
This is First Line
This is 2nd Line
This is 3rd Line

Program Time Sleeping

Program

import time
for val in range(0, 5): #loop looping from 0 to 5.
    time.sleep(2) #sleeping for 2 Second.
    print("After 2 Second!")
Output
After 2 Second!
After 2 Second!
After 2 Second!
After 2 Second!
After 2 Second!