Python: lệnh ngủ - giải thích đơn giản
Lệnh ngủ trong Python là cực kỳ thiết thực. Nó khiến một chương trình phải chờ một thời gian ngắn trước khi thực hiện các lệnh tiếp theo. Ở đây chúng tôi giải thích làm thế nào để sử dụng lệnh ngủ chính xác.
Python: Sử dụng lệnh ngủ
Bạn có thể dễ dàng thêm lệnh ngủ vào mã chương trình của mình:
- Thêm dòng "từ thời gian nhập giấc ngủ" (không có dấu ngoặc kép) vào đầu mã của bạn để bạn có thể sử dụng chức năng ngủ sau này.
- Bây giờ bạn có thể thêm lệnh "ngủ (1)" ở bất cứ đâu trong mã.
- Trong ngoặc bạn phải ghi thời gian tính bằng giây mà chương trình sẽ đợi.
- Trong trường hợp này, chương trình chờ chính xác một giây.
Thêm lời khuyên về Python trong hướng dẫn CHIP của chúng tôi
Mẹo: Trên trang chủ đề của chúng tôi về ngôn ngữ lập trình Python, bạn sẽ tìm thấy các hướng dẫn thêm về lập trình. Ở đó chúng tôi sẽ chỉ cho bạn, ví dụ, làm thế nào bạn có thể chuyển đổi một số nguyên thành một chuỗi.