In an application or program, sometimes you need to stop the execution of the next step or wait for a second. For example, block a user resend the OTP button for and 30 seconds. You can do Python wait by using the Python time module sleep() function.
Here you will learn about what function you can use and how to work on python wait.
A simple syntax for the stop a python program for a second. In the sleep() function, you have to pass the t value as seconds.
Python wait Example
Here we are importing direct sleep members from the time module, you can read this tutorial for Import from module_name.member_name.
In this example the first line print immediately but the second-line program will wait for 5 seconds.
from time import sleep print("Start: Wait") sleep(5) print("Wait is over")
Output: Start: Wait
Wait is over
Python waits for input user Input
For taking an input from a user, use in-build function input.
import time name = input('Please Enter Your Name \n') print('Wait ', 5, 'seconds for reply.') time.sleep(5) print('Hi', name, ', How are you, I am bot!')
Output: check this gif image file
It can your interview question for python programming.
Do comment if you have any doubt and suggestion on this tutorial.
Note: This example (Project) is developed in PyCharm 2018.2 (Community Edition)
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
All Python wait for input user Input Example is in Python 3, so it may change its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.