DEV Community

Cover image for Creating Delays in Python Programs
Daniel Nogueira
Daniel Nogueira

Posted on • Updated on

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

Top comments (0)