sleep() function suspends the execution of a program for a given number of seconds.
It also takes in floating point numbers as seconds to stop the execution of a program.
sleep()is defined in the
The syntax of
sleep() function is:
secs - Number of seconds the Python program is paused for execution. This argument can be
Below are two code snippets that show how the
sleep() function works. For advanced level Python, the
sleep() function is very important for multithreading.
This program sleeps for 1 second before printing Educative.
# Importing time module import time time.sleep(1) # Sleeping for one second print("Educative")
This program sleeps for 10 seconds before printing Educative.
# Importing time module import time time.sleep(10) # Sleeping for ten second print("Educative")
View all Courses