time sleep in Python

0 votes
What is the use of time.sleep() in Python?
Jul 9, 2019 in Python by Nisa
• 1,090 points
551 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, 2019 by Wajiha
• 1,960 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
1,782 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, 2019 in Python by rajesh
• 1,270 points
2,101 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
802 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,300 points
684 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,300 points
1,303 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,560 points
1,803 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,294 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,410 views
0 votes
1 answer

What is timedelta in python?

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

answered Aug 7, 2019 in Python by Wajiha
• 1,960 points
776 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, 2019 in Python by Wajiha
• 1,960 points
2,080 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