How to put time delay in Python

0 votes
I want to know how to halt the flow of a program for some time, in Python?
May 28, 2019 in Python by Shabnam
• 930 points
740 views

1 answer to this question.

0 votes

You can use sleep() method to sleep a thread for a specified amount of time. This method provides accurate and flexible way to halt a code for any period of time.

Have a look at the below given example for better understanding:

Input:

import time 

#printing the time when code execution began


print("code execution began at : ", end ="")
print(time.ctime()) 

#using sleep to halt the code execution

time.sleep(10) 

#printing the time when code execution ended

print("code execution ended at : ", end ="") 
print(time.ctime()) 

Output:

code execution began at : Tue May 28 07:41:48 2019

code execution ended at : Tue May 28 07:41:58 2019

answered May 28, 2019 by Taj
• 1,080 points

Related Questions In Python

0 votes
3 answers

How to get the current time in Python

FOLLOWING WAY TO FIND CURRENT TIME IN ...READ MORE

answered Apr 8, 2019 in Python by rajesh
• 1,270 points
2,074 views
0 votes
1 answer

How to get the current time in Python

>>> import datetime >>> datetime.datetime.now() datetime(2018, 25, ...READ MORE

answered Jul 25, 2018 in Python by Frankie
• 9,830 points
758 views
0 votes
1 answer

How to parse date/time string with timezone abbreviated name in Python?

The parse() function in dateutil can't handle ...READ MORE

answered Nov 27, 2018 in Python by Nymeria
• 3,560 points
2,259 views
0 votes
1 answer

How to calculate time interval between two time strings in Python

Try doing this - It is efficient for ...READ MORE

answered Nov 29, 2018 in Python by Nymeria
• 3,560 points

edited Dec 11, 2018 by Nymeria 3,349 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 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,790 points
4,070 views
0 votes
1 answer

How to get current time in Python?

Hi, You can use Datetime class. Input: import datetime datetime.datetime.now() Output: datetime.datetime(2019, 6, ...READ MORE

answered Jun 22, 2019 in Python by Taj
• 1,080 points
737 views
+1 vote
1 answer

How can I reverse list in Python?

Reversing a list is a commonly used ...READ MORE

answered May 13, 2019 in Python by Taj
• 1,080 points
985 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP