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实现ID3决策树算法

决策树之ID3算法及其Python实现,具体内容如下 主要内容 决策树背景知识 决策树一般构建过程 ID3算法分裂属性的选择 ID3算法流程及其优缺点分析 ID3算法Python代码...

Python3 replace()函数使用方法

描述 replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。 语法 replace()方法语法: st...

python逐行读写txt文件的实例讲解

实例如下所示: # -*-coding:utf-8-*- import os file_obj = open("test2.txt") all_lines = file_obj.re...

利用Python命令行传递实例化对象的方法

一、前言 在开发过程中,遇到了这样一个情况:我们需要在脚本中通过 suprocess.call 方法来启动另外一个脚本(脚本 B),当然啦,还得传递一些参数。在这些参数中,有一个需要传...

Python3搜索及替换文件中文本的方法

本文实例讲述了Python3搜索及替换文件中文本的方法。分享给大家供大家参考。具体实现方法如下: # 将文件中的某个字符串改变成另一个 # 下面代码实现从一个特定文件或标准输入读取...