Python 編程中使用 time 模塊可以讓程序休眠,具體方法是time.sleep(秒數),其中“秒數”以秒為單位,可以是小數,0.1秒則代表休眠100毫秒。
# 例1:循環輸出休眠1秒
import time
i = 1
while i <= 3:
print i # 輸出i
i += 1
time.sleep(1) # 休眠1秒
# 例1:循環輸出休眠100毫秒
import time
i = 1
while i <= 3:
print i # 輸出i
i += 1
time.sleep(0.1) # 休眠0.1秒