Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีสร้างหน่วงเวลา (Time Delay) ใน Python

ใช้ฟังก์ชัน sleep() จากโมดูล time เพื่อหน่วงเวลาเป็นวินาที

time.sleep(sec)

ตัวอย่าง

import time
print("current time:", time.ctime())
time.sleep(10)  # หน่วง 10 วินาที
print("after 10 sec:", time.ctime())