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判断列表是否已排序的各种方法及其性能分析

声明 本文基于Python2.7语言,给出判断列表是否已排序的多种方法,并在作者的Windows XP主机(Pentium G630 2.7GHz主频2GB内存)上对比和分析其性能表现...

python Pandas如何对数据集随机抽样

python Pandas如何对数据集随机抽样

摘要:有时候我们只需要数据集中的一部分,并不需要全部的数据。这个时候我们就要对数据集进行随机的抽样。pandas中自带有抽样的方法。 应用场景: 我有10W行数据,每一行都11列的属性...

python 定时器,实现每天凌晨3点执行的方法

如下所示: ''' Created on 2018-4-20 例子:每天凌晨3点执行func方法 ''' import datetime import threading def...

详解pycharm连接不上mysql数据库的解决办法

详解pycharm连接不上mysql数据库的解决办法

问题描述 环境:ubuntu18.04,mysql5.7 今天在ubuntu下使用pycharm连接mysql,发现连接不上 这不是缺少驱动吗?下载之! 下好之后点进去 连接 点击...

关于pip的安装,更新,卸载模块以及使用方法(详解)

在Python的学习过程中,肯定会遇到很多安装模块的地方,可以使用easy_install安装,但是easy_install相对于pip而言,最大的缺陷就是它所安装的模块是不能够卸载的,...