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).