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中函数的参数传递

1.普通的参数传递 >>> def add(a,b): return a+b >>> print add(1,2) 3 >&g...

python实现360的字符显示界面

复制代码 代码如下:#!/usr/bin/python  #-*-coding:utf-8-*- from push_button import *from clabel im...

Python计时相关操作详解【time,datetime】

本文实例讲述了Python计时相关操作。分享给大家供大家参考,具体如下: 内容目录: 1. 时间戳 2. 当前时间 3. 时间差 4. python中时间日期格式化符号 5. 例子 一、...

python实现杨氏矩阵查找

本文实例为大家分享了python实现杨氏矩阵查找的具体代码,供大家参考,具体内容如下 问题描述: 在一个m行n列二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的...

Python设计模式之适配器模式原理与用法详解

Python设计模式之适配器模式原理与用法详解

本文实例讲述了Python设计模式之适配器模式原理与用法。分享给大家供大家参考,具体如下: 适配器模式(Adapter Pattern):将一个类的接口转换成为客户希望的另外一个接口....