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程序设计有所帮助。

相关文章

Python使用Turtle模块绘制五星红旗代码示例

Python使用Turtle模块绘制五星红旗代码示例

在Udacity上课时学到了python的turtle方法,这是一个很经典的用来教小孩儿编程的图形模块,最早起源于logo语言。python本身内置了这个模块,其可视化的方法可以帮助小孩...

python学习笔记--将python源文件打包成exe文件(pyinstaller)

pyinstaller 库的使用 PyInstaller是一个十分有用的第三方库,它能够在Windows、Linux、Mac OS X 等操作系统下将 Python 源文件打包,通过对源...

python 定时器,轮询定时器的实例

python 定时器默认定时器只执行一次,第一个参数单位S,几秒后执行 import threading def fun_timer(): print('Hello Timer...

Django实现WebSSH操作物理机或虚拟机的方法

Django实现WebSSH操作物理机或虚拟机的方法

我想用它替换掉xshell、crt之类的工具 WebSSH操作物理机或虚拟机 上篇文章给大家介绍详解基于django实现的webssh简单例子,有小伙伴说咖啡哥,我们现在还没有用上Kub...

对Python3之进程池与回调函数的实例详解

进程池 代码演示 方式一 from multiprocessing import Pool def deal_task(n): n -= 1 return n if __...