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本地与全局命名空间用法。分享给大家供大家参考。具体如下: x = 1 def fun(a): b=3 x=4 def sub(c): d...

如何用Python做一个微信机器人自动拉群

如何用Python做一个微信机器人自动拉群

引言 微信群的用户添加逻辑是 —— 当群人数达到100人后,用户无法再通过扫描群二维码加入,只能让用户先添加群内联系人微信,再由联系人把用户拉进来。这样,联系人员的私人微信会添加大量陌...

python conda操作方法

conda 虚拟环境安装 List item conda env list #查看已安装虚拟环境 coda创建虚拟环境非常方便:官方教程:https://conda.io/project...

Python实现对象转换为xml的方法示例

本文实例讲述了Python实现对象转换为xml的方法。分享给大家供大家参考,具体如下: # -*- coding:UTF-8 -*- ''''' Created on 2010-4-...

在SQLite-Python中实现返回、查询中文字段的方法

博主在这个问题上卡了挺久的,贴出来解决方法帮助需要的朋友,直接上代码(测试环境:win10+Python2.7): # coding=utf-8 import sqlite3...