Sleep, Wait or Pause Python Code for Seconds with time.sleep()

To add a delay to your Python code you can use the sleep() function from Python's time module.

import time

countdown = [3, 2, 1, 'Go!!!']

for item in countdown:
    print(item)
    time.sleep(1)

# 3
# 2
# 1
# Go!!!

The sleep module takes a single argument. This can be either an integer for the number of seconds to sleep or a float if you want to have sub-second resolution such as 0.5 of a second, 1.75 seconds and so on. Using the sleep() function suspends the processing of the thread which uses almost no processing power and allows other processes to run while it sleeps.


Join the Able Developer Network

If you liked this post you might be interested in the Able developer network, a new place for developers to blog and find jobs.