top of page

sleep()

The sleep() function suspends (waits) execution of the current thread for a given number of seconds.

Python has a module named time which provides several useful functions to handle time-related tasks. One of the popular functions among them is sleep().

The sleep() function suspends execution of the current thread for a given number of seconds.

 

import time print("Printed immediately.") time.sleep(2.4) print("Printed after 2.4 seconds.") Here's how this program works:

  • "Printed immediately" is printed

  • Suspends (Delays) execution for 2.4 seconds.

  • "Printed after 2.4 seconds" is printed.

As you can see from the above example, sleep() takes a floating-point number as an argument.

 
 

My code:

import time for i in range(6): print(i, " Mississippi") time.sleep(1) print("Ready or not, here I come!")

 

Expected output:

1 Mississippi

2 Mississippi

3 Mississippi

4 Mississippi

5 Mississippi

bottom of page