python中sleep函数用法实例分析

yipeiwu_com6年前Python基础

本文实例讲述了python中sleep函数用法。分享给大家供大家参考。具体如下:

Python中的sleep用来暂停线程执行,单位为秒

#-----------------------------------
#      Name: sleep.py
#     Author: Kevin Harris
# Last Modified: 02/13/04
#  Description: This Python script demonstrates
#         how to use the sleep()
#         function.
#-----------------------------------
from time import sleep
print( "We'll start off by sleeping 5 seconds" )
sleep( 5 )
print( "Ok, time to wake up!" )
wait_time = int( input( "How much longer would you like to sleep? " ) )
while wait_time > 0:
  print("Ok, we'll sleep for "+str(wait_time)+" more seconds...")
  sleep( wait_time )
  wait_time = int(input("How much longer would you like to sleep?"))
print( "We're done!" )

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Pytorch之parameters的使用

1.预构建网络 class Net(nn.Module): def __init__(self): super(Net, self).__init__() # 1...

python创建学生管理系统

python创建学生管理系统

使用python创建学生管理系统,供大家参考,具体内容如下 创建学生管理系统,可谓是学习编程最基础的一小步。 主要是分为以下几个思路: 接下来直接上源码 #!/usr/bin/py...

使用Python的Django框架结合jQuery实现AJAX购物车页面

使用Python的Django框架结合jQuery实现AJAX购物车页面

Django中集成jquery 首先,静态的资源通常放入static文件夹中: static/ css/ djquery.css samples/...

用python写一个windows下的定时关机脚本(推荐)

由于本人经常使用笔记本共享WiFi,但是又不想笔记本开机一夜(为了低碳环保嘛 ~_~!),所以每次都要用使用DOS命令关机,感觉好麻烦。正好最近在学习Python,于是决定用python...

Python实现批量转换文件编码的方法

本文实例讲述了Python实现批量转换文件编码的方法。分享给大家供大家参考。具体如下: 这里将某个目录下的所有文件从一种编码转换为另一种编码,然后保存 import os impor...