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中dict()的高级用法实现

python中dict()的高级用法实现

collections中defaultdict的用法 一、字典的键映射多个值 将下面的列表转换成字典 一个字典就是一个键对应一个单值得映射,而上面的列表中有相同的键,如果你想要一个键映...

使用Python进行AES加密和解密的示例代码

高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代...

python切片的步进、添加、连接简单操作示例

本文实例讲述了python切片的步进、添加、连接简单操作。分享给大家供大家参考,具体如下: 步进切片: #coding:utf-8 a="123456" print a[::-1]...

Python在cmd上打印彩色文字实现过程详解

Python在cmd上打印彩色文字实现过程详解

前言 在Windows上编写python程序时,有时候需要对输出的文字颜色进行设置,特别是日志显示,不同级别的日志设置不同的颜色进行展示可以直观查看。本文主要描述通过ctypes.win...

分享Python开发中要注意的十个小贴士

大家请注意:这篇文中假设我们都用的是Python 3 1. 列表推导式 你有一个list:bag = [1, 2, 3, 4, 5] 现在你想让所有元素翻倍,让它看起来是这个样子: [2...