How to Pause, Stop, Wait or Sleep your Python
Published on Aug. 22, 2023, 12:16 p.m.
To pause or delay the execution of a Python program, you can use the time.sleep()
function. Here’s an example of how to use time.sleep()
to pause the program for 5 seconds:
import time
print("Starting program...")
time.sleep(5)
print("5 seconds have passed!")
In the example above, time.sleep(5)
pauses the program for 5 seconds before the final print statement is executed.
Note that time.sleep()
takes the number of seconds to pause as an argument, which can be a floating point value if you need to pause for less than a whole number of seconds.
I hope that helps! Let me know if you have any further questions.