Creating Delays in Python Programs

udanielnogueira

Daniel Nogueira

Posted on January 4, 2023

Creating Delays in Python Programs

Short breaks can be fun and functional in some programs. Creating a waiting time before displaying a text, for example, can make the process of using that program more real.

For that, let's import the sleep() method from the time module:

from time import sleep
Enter fullscreen mode Exit fullscreen mode

And now just call the sleep() method specifying the time in seconds:

# 3 second delay
sleep(3)

# 1 minute delay
sleep(60)
Enter fullscreen mode Exit fullscreen mode

Example of how delays can make a program more real:

print('Jo')
sleep(1)
print('Ken')
sleep(1)
print('Po')
sleep(1)
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
udanielnogueira
Daniel Nogueira

Posted on January 4, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related