深度阅读

How to Pause, Stop, Wait or Sleep your Python

作者
作者
2023年08月22日
更新时间
6.41 分钟
阅读时间
0
阅读量

To pause or delay the execution of a Python program, you can use the time.sleep() function. Here’s an example of how to use time.sleep() to pause the program for 5 seconds:

import time

print("Starting program...")
time.sleep(5)
print("5 seconds have passed!")

In the example above, time.sleep(5) pauses the program for 5 seconds before the final print statement is executed.

Note that time.sleep() takes the number of seconds to pause as an argument, which can be a floating point value if you need to pause for less than a whole number of seconds.

I hope that helps! Let me know if you have any further questions.

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。