Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
sleep()

How to use sleep() function in Python

Educative Answers Team

The 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 time module.

svg viewer

Syntax

The syntax of sleep() function is:

time.sleep(secs)

Parameter

secs - Number of seconds the Python program is paused for execution. This argument can be int or float.

Examples

Below are two code snippets that show how the sleep() function works. For advanced level Python, the sleep() function is very important for multithreading.

Sleeping for one second

This program sleeps for 1 second before printing Educative.

# Importing time module
import time 

time.sleep(1) # Sleeping for one second
print("Educative")

Sleeping for ten seconds

This program sleeps for 10 seconds before printing Educative.

# Importing time module
import time 

time.sleep(10) # Sleeping for ten second
print("Educative")

RELATED TAGS

python
sleep()
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring