Can the execution of statements in Python be delayed?

rectangletangle picture rectangletangle · Jul 25, 2010 · Viewed 25.4k times · Source

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

Answer

NullUserException picture NullUserException · Jul 25, 2010

time.sleep(seconds)

import time

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