Delaying an Operation in Python
There are situations when you want an operation to be performed after a certain period of time. To solve this problem, you should use the sleep
method of the time
module.
Let's output a message to the console after 5
seconds. To do this, first apply the sleep
method, specifying the desired delay in seconds in its parameter. And then specify the output of the message to the console:
time.sleep(5)
print('!!!') # '!!!' in 5 seconds
Display your name in 15
seconds.
Given a list:
lst = ['a', 'b', 'c', 'd']
Print all its elements every 3
seconds.