1.7. Syntax errors
Python can only execute a program if the program is syntactically correct; otherwise, the process fails and returns an error message. Syntax refers to the structure of a program and the rules about that structure. For example, in English, a sentence must begin with a capital letter and end with a period. this sentence contains a syntax error.
For most readers, a few syntax errors are not a significant problem, which is why we can read the poetry of e. e. cummings without problems. Python is not so forgiving. If there is a single syntax error anywhere in your program, Python will display an error message and quit. You will not be able to complete the execution of your program. During the first few weeks of your programming career, you will probably spend a lot of time tracking down syntax errors. However, as you gain experience, you will make fewer errors and you will also be able to find your errors faster.
For most readers, a few syntax errors are not a significant problem, which is why we can read the poetry of e. e. cummings without problems. Python is not so forgiving. If there is a single syntax error anywhere in your program, Python will display an error message and quit. You will not be able to complete the execution of your program. During the first few weeks of your programming career, you will probably spend a lot of time tracking down syntax errors. However, as you gain experience, you will make fewer errors and you will also be able to find your errors faster.
Python chỉ có thể thực hiện một chương trình nếu chương trình là cú pháp chính xác; Nếu không, quá trình không thành công và trả về một thông báo lỗi. Cú pháp đề cập đến cấu trúc của một chương trình và các quy tắc về cấu trúc đó. Ví dụ, bằng tiếng Anh, một câu phải bắt đầu bằng một chữ cái hoa và kết thúc bằng một dấu chấm câu, (nếu không) thì câu này sẽ là lỗi cú pháp.
Đối với hầu hết mọi người, một vài lỗi cú pháp không phải là một vấn đề đáng kể, đó là lý do tại sao chúng ta có thể đọc thơ của E. Cummings mà không có thấy có vấn đề. (nhưng) Python không bỏ qua nó. Nếu có một lỗi cú pháp duy nhất bất cứ nơi nào trong chương trình của bạn, Python sẽ hiển thị một thông báo lỗi và bỏ qua các bước tiếp theo(có thể hiểu là ko chạy được tiếp). Bạn sẽ không thể hoàn thành việc thực hiện chương trình của bạn. Trong vài tuần đầu tiên của (khi bắt đầu học) lập trình của bạn, có thể bạn sẽ dành rất nhiều thời gian kiểm tra các lỗi cú pháp. Tuy nhiên, khi bạn có được kinh nghiệm, bạn sẽ làm cho ít lỗi hơn và bạn cũng sẽ có thể tìm thấy lỗi của bạn nhanh hơn.
References:
http://interactivepython.org/runestone/static/thinkcspy/index.html
References:
http://interactivepython.org/runestone/static/thinkcspy/index.html
Nhận xét
Đăng nhận xét