How to add a certain time delay to the code using Python

0 votes
Hi all. Pretty simple - My requirement is that I want to know how I could put a certain time delay of a particular duration into the code of my Python script.

I am working on learning Python and using this for a project of mine.

All help appreciated!
Feb 14, 2019 in Python by Anirudh
• 2,080 points
205 views

2 answers to this question.

0 votes

It is really simple. Check out the following code snippet:

import time
time.sleep(5)   # Delays for 5 seconds. You can also use a float value.

Also, check this out. I have another example for you where a piece of code is run once in a minute.

import time
while True:
    print("This prints once a minute.")
    time.sleep(60) # Delay for 1 minute (60 seconds).

Hope this helped!

answered Feb 14, 2019 by Nymeria
• 3,520 points
0 votes
You can use
time.sleep(duration in second)
answered Feb 14, 2019 by Shashank
• 1,370 points

Related Questions In Python

0 votes
2 answers

how to print the current time using python?

print(datetime.datetime.today()) READ MORE

answered Feb 14, 2019 in Python by Shashank
• 1,370 points
176 views
0 votes
1 answer

How to correctly return an a dictionary as an output in zappier code using python?

David here, from the Zapier Platform team. ...READ MORE

answered Dec 3, 2018 in Python by charlie_brown
• 7,780 points
448 views
0 votes
2 answers

How can I write a program to add two numbers using functions in python?

there is sum() function as a built ...READ MORE

answered Oct 24, 2020 in Python by anonymous
12,730 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,834 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,416 views
0 votes
3 answers

How to get the return value from a thread using python?

FWIW, the multiprocessing module has a nice interface for ...READ MORE

answered Dec 15, 2020 in Python by Roshni
• 10,420 points
52,819 views
0 votes
1 answer

How to use read a WSDL file from the file system using Python suds?

Hi, good question. It is a very simple ...READ MORE

answered Jan 21, 2019 in Python by Nymeria
• 3,520 points
3,597 views