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计算两个地址之间的距离方法

我们调用高德地图的API来计算经纬度 #计算地址经纬度 import requests def geocode(address): parameters = {'address':...

python 默认参数问题的陷阱

python 里面一个常见的陷阱就是函数的默认参数问题。如下: def func(mylist = []): mylist.append(1) return mylist...

Python操作SQLite/MySQL/LMDB数据库的方法

1.概述 1.1前言   最近在存储字模图像集的时候,需要学习LMDB,趁此机会复习了SQLite和MySQL的使用,一起整理在此。 1.2环境   使用win7,Python 3.5....

Python高级特性 切片 迭代解析

Python高级特性 切片 迭代解析

切片:方便截取list、tuple、字符串部分索引的内容 正序切片 语法:dlist = doList[0:3]表示,从索引0开始取,直到索引3为止,但不包括索引3。即索引0,1,2...

Python入门及进阶笔记 Python 内置函数小结

内置函数 常用函数 1.数学相关 •abs(x) abs()返回一个数字的绝对值。如果给出复数,返回值就是该复数的模。 复制代码 代码如下: >>>prin...