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

相关文章

人工神经网络算法知识点总结

人工神经网络算法知识点总结

人工神经网络的许多算法已在智能信息处理系统中获得广泛采用,尤为突出是是以下4种算法:ART网络、LVQ网络、Kohonen网络Hopfield网络,下面就具体介绍一下这这四种算法: 1....

Python Web框架Flask中使用七牛云存储实例

对于小型站点,使用七牛云存储的免费配额已足够为站点提供稳定、快速的存储服务 七牛云存储已有Python SDK,对它进行简单封装后,就可以直接在Flask中使用了,项目代码见GitHub...

跟老齐学Python之集合(set)

回顾一下已经了解的数据类型:int/str/bool/list/dict/tuple 还真的不少了. 不过,python是一个发展的语言,没准以后还出别的呢.看官可能有疑问了,出了这么多...

python中使用while循环的实例

python中使用while循环的实例

python中for循环用于针对集合中的每个元素的一个代码块,而while循环能实现满足条件下的不断运行。 使用while循环时,由于while只要满足条件就会执行代码,故必须指定结束条...

python使用turtle库与random库绘制雪花

python使用turtle库与random库绘制雪花

本文实例为大家分享了python绘制雪花的具体代码,供大家参考,具体内容如下 代码非常容易理解,画着玩玩还是可以的。直接上代码 # -*- coding: utf-8 -*- """...