top of page

sleep()

The sleep() function suspends (waits) execution of the current thread for a given number of seconds.

Python has a module named time which provides several useful functions to handle time-related tasks. One of the popular functions among them is sleep().

The sleep() function suspends execution of the current thread for a given number of seconds.

 

import time print("Printed immediately.") time.sleep(2.4) print("Printed after 2.4 seconds.") Here's how this program works:

  • "Printed immediately" is printed

  • Suspends (Delays) execution for 2.4 seconds.

  • "Printed after 2.4 seconds" is printed.

As you can see from the above example, sleep() takes a floating-point number as an argument.

 
 

My code:

import time for i in range(6): print(i, " Mississippi") time.sleep(1) print("Ready or not, here I come!")

 

Expected output:

1 Mississippi

2 Mississippi

3 Mississippi

4 Mississippi

5 Mississippi

aboutME

I am John Fan Zhang, a data analyst and finance researcher. I hold a PhD in finance, CFA charter and full membership of CFA New Zealand Society. I have fifteen-year experience in corporate investment and eight-year experience in advanced data analysis. My research focuses on the effect of social psychology (culture) on financial decisions. Finance research involves heaps of data analyses that lead me to the data field. I am a Microsoft Certified Solutions Expert (MCSE): Data Management and Analytics (Excel, Power BI, and SQL). Aside from Excel, Power BI and SQL, I am also familiar with econometric tools such as Stata, Eviews, and MATLAB. I use OX and Python for programming. I am an active data community event participant, volunteer, speaker, moderator, program reviewer, including PASS Marathon 2020, Global AI BootCamp Auckland 2019, SQL Saturday Auckland (2017, 2018, 2019), and Definity Conference (2018, 2019, 2020, Auckland, New Zealand).

Auckland, New Zealand

  • Google Site
  • Twitter
  • LinkedIn

©2016 BY JOHN'S DATA STORY

bottom of page