If you need to suspend code execution for some period of time you can use the sleep()
function.
The sleep()
function suspend execution of the calling thread for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep time.
Example: print number every 2 seconds
import time for i in range(1, 5): current_time = time.localtime() print(f'{time.strftime("%I:%M:%S", current_time)} - {str(i)}') time.sleep(2)
Result:
05:52:57 - 1
05:52:59 - 2
05:53:01 - 3
05:53:03 - 4