The time.sleep()
method in Python is used to pause the execution of a program for a specified number of seconds. The argument placed in the parentheses should be a number representing the duration of the sleep in seconds. This can be a whole number (for whole seconds) or a floating-point number (for fractional seconds).
Here are a few examples:
-
To sleep for 5 seconds:
import time time.sleep(5)
-
To sleep for 0.5 seconds (500 milliseconds):
import time time.sleep(0.5)
-
To sleep for 2.25 seconds:
import time time.sleep(2.25)
Make sure to import the time
module before using time.sleep()
.