python中sleep函数用法实例分析

yipeiwu_com5年前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基于Tkinter库实现简单文本编辑器实例

本文实例讲述了python基于Tkinter库实现简单文本编辑器的方法。分享给大家供大家参考。具体实现方法如下: ## {{{ http://code.activestate.com...

使用NumPy和pandas对CSV文件进行写操作的实例

数组存储成CSV之类的区隔型文件: 下面代码给随机数生成器指定种子,并生成一个3*4的NumPy数组 将一个数组元素的值设为NaN: In [26]: import numpy a...

python使用phoenixdb操作hbase的方法示例

今天看看怎样在 python 中使用 phoenixdb 来操作 hbase 安装 phoenixdb 库 pip install phoenixdb 例子 首先启动 que...

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

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

pytorch1.0中torch.nn.Conv2d用法详解

Conv2d的简单使用 torch 包 nn 中 Conv2d 的用法与 tensorflow 中类似,但不完全一样。 在 torch 中,Conv2d 有几个基本的参数,分别是 in_...