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

1 min read

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:

# 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.

Author picture
Rhett Trickett

Founder at Able

@rhett RhettTrickett rhetttrickett

Join the discussion

Able is a developer community where people build their coding knowledge and careers.

Join with GitHub Join with Twitter