The .sleep() method suspends execution of the current thread for a given period of time in seconds.
duration parameter is given in seconds, and suspends/delays execution of the thread.
The following example will delay execution of the next
print() statement by 2.4 seconds:
import timeprint("Printed immediately.")time.sleep(2.4)print("Printed after 2.4 seconds.")
The output will be:
Printed immediately.Printed after 2.4 seconds.
The following example will output time after a 5 second delay from current time (provided by the
- Anonymous contributorAnonymous contributor2 total contributions
- Anonymous contributor