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 in Python by Anirudh
• 2,060 points
26 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 by Nymeria
• 3,500 points
0 votes
You can use
time.sleep(duration in second)
answered Feb 14 by Shashank
• 1,350 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 in Python by Shashank
• 1,350 points
33 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,710 points
89 views
0 votes
1 answer
0 votes
1 answer

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

def add(a,b):      return a + b #when i call ...READ MORE

answered May 20 in Python by Mohammad
• 1,500 points
25 views
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 132 views
+4 votes
6 answers
0 votes
1 answer

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

You don't need to change your existing ...READ MORE

answered Dec 3, 2018 in Python by Nymeria
• 3,500 points

edited Dec 19, 2018 by Nymeria 6,806 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 in Python by Nymeria
• 3,500 points
295 views