描述
Python時間方法sleep()暫停執行給定的秒數。參數可能是一個浮點數,以指示更精確的睡眠時間。
實際掛起時間可能比請求的短,因為在執行該信號的捕獲例程後,任何捕獲的信號都將終止 sleep()。
用法
以下是語法sleep()方法 -
time.sleep(t)
參數
t- 這是暫停執行的秒數。
返回值
此方法不返回任何值。
示例
下麵的例子展示了 sleep() 方法的用法。
#!/usr/bin/python
import time
print "Start:%s" % time.ctime()
time.sleep( 5 )
print "End:%s" % time.ctime()
當我們運行上麵的程序時,它會產生以下結果 -
Start:Tue Feb 17 10:19:18 2009 End:Tue Feb 17 10:19:23 2009
相關用法
- Python time strftime()用法及代碼示例
- Python time strptime()用法及代碼示例
- Python time ctime()用法及代碼示例
- Python time mktime()用法及代碼示例
- Python time localtime()用法及代碼示例
- Python time clock()用法及代碼示例
- Python time asctime()用法及代碼示例
- Python time altzone()用法及代碼示例
- Python time tzset()用法及代碼示例
- Python time time()用法及代碼示例
- Python time replace()用法及代碼示例
- Python time gmtime()用法及代碼示例
- Python time.monotonic()用法及代碼示例
- Python time.asctime()用法及代碼示例
- Python time.ctime()用法及代碼示例
- Python time.perf_counter()用法及代碼示例
- Python time.get_clock_info()用法及代碼示例
- Python time.gmtime()用法及代碼示例
- Python time.time()用法及代碼示例
- Python time.mktime()用法及代碼示例
注:本文由純淨天空篩選整理自 Python time sleep() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。