While developing or using a Python application or script we may need some delay. The delay can be created for different reasons in different ways. In this tutorial, we will examine how to create a delay in Python.
time.sleep() Method
The time module provides different helpful methods for time-related operations. The sleep() method can be used to delay the execution of the python script or application. The sleep() method accepts the delay duration as a parameter. The delay duration is expressed as milliseconds. As an example 3000 milliseconds equal to 3 seconds.
import time
print("We will wait for 3 seconds or 3000 milliseconds")
time.sleep(3000)
Matplot pause() Method
The matplotlib provides the pause method which is very similar to the time sleep() method. The pause() method can be used to delay the execution of the python script or application. The pause() method accepts delay duration as seconds.
import matplotlib import pyplot as p
print("We will wait for 5 seconds or 5000 milliseconds")
p.pause(5)