Search code examples
pythonsleepdelaytiming

Can the execution of statements in Python be delayed?


I want it to run the first line print 1 then wait 1 second to run the second command print 2, etc.

Pseudo-code:

print 1
wait(1 seconds)
print 2
wait(0.45 seconds)
print 3
wait(3 seconds)
print 4

Solution

  • time.sleep(seconds)

    import time
    
    print 1
    time.sleep(1)
    print 2
    time.sleep(0.45)
    print 3
    time.sleep(3)
    print 4