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实现图片彩色转化为素描

python实现图片彩色转化为素描

本文实例为大家分享了Python将图片彩色转化为素描的具体代码,供大家参考,具体内容如下 第一种: from PIL import Image, ImageFilter, Image...

Python3.5 Pandas模块之DataFrame用法实例分析

Python3.5 Pandas模块之DataFrame用法实例分析

本文实例讲述了Python3.5 Pandas模块之DataFrame用法。分享给大家供大家参考,具体如下: 1、DataFrame的创建 (1)通过二维数组方式创建 #!/...

python获取酷狗音乐top500的下载地址 MP3格式

python获取酷狗音乐top500的下载地址 MP3格式

下面先给大家介绍下python获取酷狗音乐top500的下载地址 MP3格式,具体代码如下所示: # -*- coding: utf-8 -*- # @Time : 2018/4/1...

python编码总结(编码类型、格式、转码)

python编码总结(编码类型、格式、转码)

本文详细总结了python编码。分享给大家供大家参考,具体如下: 【所谓unicode】 unicode是一种类似于符号集的抽象编码,它只规定了符号的二进制代码,却没有规定这个二进制代码...

Python多进程池 multiprocessing Pool用法示例

本文实例讲述了Python多进程池 multiprocessing Pool用法。分享给大家供大家参考,具体如下: 1. 背景 由于需要写python程序, 定时、大量发送htttp请求...