-3

Let's say we have two commands:

print("Hello")
print("How are you?")

If we execute this, we will get these two sentences printed.

I want the command 2 to be executed after 5 seconds the command 1 is executed. Is it possible to achieve this in Python?

YakovL
  • 7,557
  • 12
  • 62
  • 102
  • please specify if you want to just wait for 5 seconds or run the second command in an async manner, meaning that if you put a 3d command after the 2d one, the will get executed in the order: `1, 3, [delay] 2` – YakovL Dec 18 '18 at 20:41
  • 2
    Possible duplicate of [Correct way to pause Python program](https://stackoverflow.com/questions/11552320/correct-way-to-pause-python-program) – takendarkk Dec 18 '18 at 20:41
  • Haven't checked it! Thanks for informing my mistake! – siddarth kothur Dec 18 '18 at 21:43

3 Answers3

1
import time     

print("Hello")
time.sleep(5)
print("How are you?")
Wes Doyle
  • 2,199
  • 3
  • 17
  • 32
1
import time
time.sleep(5)

see time

ehacinom
  • 8,070
  • 7
  • 43
  • 65
0

First, you need to import the time function the only code you need is:

time.sleep(5) 

this function will make the code sleep (delay)

so you can just us

import time

print('Hello') 
time.sleep(5) 
print('How are you')

this will first execute the first line then sleep for 5 seconds then print how are you

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 12 '22 at 18:16