VOOZH about

URL: https://www.geeksforgeeks.org/python/sleep-in-python/

⇱ time.sleep() in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

time.sleep() in Python

Last Updated : 11 Jul, 2025

Python time sleep() function suspends execution for the given number of seconds.

Syntax of time sleep()

Syntax : sleep(sec)

Parameters : 

  • sec : Number of seconds for which the code is required to be stopped.

Returns : VOID. 

Sometimes, there is a need to halt the flow of the program so that several other executions can take place or simply due to the utility required. sleep() can come in handy in such a situation which provides an accurate and flexible way to halt the flow of code for any period of time. This function discusses the insight of this function.

Example 1: Creating a Time Delay in seconds

The start time and end time will be printed with 6 seconds delay.

Output: 

The time of code execution begin is : Mon Apr 9 20:57:10 2018
The time of code execution end is : Mon Apr 9 20:57:16 2018

Example 2: Creating a Time Delay in minutes

The list will be displayed after the delay of 3 minutes

Output:

After the delay of 3 minutes, the list will be displayed as:

['Java', 'C++', 'Python', 'Javascript', 'C#', 'C', 'Kotlin']

Application of time.sleep() 

There are many applications that sleep() is used for. Be its execution of the background thread which is repeated at regular intervals, this can be implemented with the help of sleep(). Another popular application is using sleep() to print the words letter by letter for a good user interface. The latter is represented in the code below.

Example 1: Creating Time Delay in the Python loop

Output:

GeeksForGeeks

Note: Visible effect of sleep() can be seen in the local editor.

Example 2: Creating Time Delay in Python List 

Output:

After the delay of 5 seconds, we will get the output as:

['Jai', 'Shree', 'RAM', 5, 'August', 2020]

Example 3: Creating Time Delay in Python Tuple

Output:

After the delay of 4 seconds, we will get the output as:

('Anil Kumbl', 'Sachin Tendulkar', 'Sunil Gavaskar', 'Rahul Dravid',
'Mahendra Singh Dhoni', 'Dennis Lillee', 'Muttiah Muralitharan', 'Shane Warne')

Example 4: Time Delay in a List Comprehension

Output:

After every 7  seconds, the items on the list will be displayed as:

Anil Kumble
Sachin Tendulkar
Sunil Gavaskar
Rahul Dravid
Mahendra Singh Dhoni
Dennis Lillee
Muttiah Muralitharan
Shane Warne

Example 5: Creating Multiple Time Delays

Output:

After the delay of 5 seconds, the list will be displayed as:

['Java', 'C++', 'Python', 'Javascript', 'C#', 'C', 'Kotlin']

Then after every 13 seconds, the items on the list will be displayed as:

Java
C++
Python
Javascript
C#
C
Kotlin
Comment
Article Tags: