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标准库笔记struct模块的使用

最近在学习python网络编程这一块,在写简单的socket通信代码时,遇到了struct这个模块的使用,当时不太清楚这到底有和作用,后来查阅了相关资料大概了解了,在这里做一下简单的总结...

python 七种邮件内容发送方法实例

一、文件形式的邮件复制代码 代码如下:#!/usr/bin/env python3#coding: utf-8import smtplibfrom email.mime.text imp...

python生成ppt的方法

python生成ppt的方法

本文主要介绍如何通过python生成ppt文件,以及借助ppt模板来生成ppt 环境 python 3 python-pptx 安装 pip3 install python-p...

python框架flask表单实现详解

这篇文章主要介绍了python框架flask表单实现详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 表单 表单用于注册,修改用户数...

Python协程操作之gevent(yield阻塞,greenlet),协程实现多任务(有规律的交替协作执行)用法详解

本文实例讲述了Python 协程操作之gevent(yield阻塞,greenlet),协程实现多任务(有规律的交替协作执行)用法。分享给大家供大家参考,具体如下: 实现多任务:进程消耗...