To add a delay or pause in a Python script, you can use the time
module and the time.sleep()
function. The time.sleep()
function suspends the execution of the script for a specified number of seconds.
Here's an example of how to use the time.sleep()
function to add a delay to a Python script:
import time # Add a delay of 5 seconds time.sleep(5) print("Delay finished")
This will pause the script for 5 seconds, and then it will print Delay finished
.
It's important to note that the time.sleep()
function blocks the execution of the script, which means that the script will not be able to respond to input or perform any other tasks while the delay is active. If you need to perform other tasks while the delay is active, you may need to use a different approach, such as using threads or asyncio.
Consult the Python documentation and online resources for more information on how to use the time
module and the time.sleep()
function to add a delay to a Python script.