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 in Python by Shabnam
• 800 points
19 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 by Taj
• 920 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 in Python by rajesh
• 1,210 points
45 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,810 points
35 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,500 points
134 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,500 points

edited Dec 11, 2018 by Nymeria 102 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 128 views
+4 votes
6 answers
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 21 in Python by Taj
• 920 points
20 views
+1 vote
1 answer

How can I reverse list in Python?

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

answered May 13 in Python by Taj
• 920 points
27 views