time.sleep() in Python

0 votes
What is the use of time.sleep() in Python?
Jul 9 in Python by Nisa
• 1,090 points
22 views

1 answer to this question.

0 votes

Sleep function plays a very important role in a situation where we want to halt the program flow and let other executions happen. This function is defined in both versions of python i.e 2 and 3. It belongs to the time module of Python. It basically adds a delay to the execution and it will only pause the current thread and not the whole program. 

EXAMPLE:

import time # import time module

sleep_time = 1  # time to add delay after first print statement

print('Hello')

time.sleep(sleep_time)  # sleep time

print('Edureka!')

If the above code is executed it will add a delay in the program thus, the next statement will be executed after 1 second(s).

answered Jul 9 by Wajiha
• 1,840 points

Related Questions In Python

0 votes
1 answer

Create time lag in Python

import time time.sleep(10) READ MORE

answered May 2, 2018 in Python by Nietzsche's daemon
• 4,260 points
157 views
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
56 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
39 views
0 votes
1 answer

Get the Current time in Python

To get the current date and time ...READ MORE

answered Oct 3, 2018 in Python by SDeb
• 13,160 points
45 views
0 votes
1 answer

Time delay in Python

The following code will delay it for ...READ MORE

answered Oct 4, 2018 in Python by SDeb
• 13,160 points
53 views
0 votes
1 answer

Is multi-threading supported in Python and can it speed up execution time as well?

The GIL does not prevent threading. All ...READ MORE

answered Nov 22, 2018 in Python by Nymeria
• 3,520 points
138 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,520 points
163 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,520 points

edited Dec 11, 2018 by Nymeria 117 views
0 votes
1 answer

What is timedelta in python?

It represents a duration which is basically ...READ MORE

answered Aug 7 in Python by Wajiha
• 1,840 points
19 views
0 votes
1 answer

Slicing a list using a variable, in Python

Yes its possible. Use the following piece ...READ MORE

answered Jul 2 in Python by Wajiha
• 1,840 points
18 views