232
Debugging
If you are building the program incrementally, you should have a good idea about
where the error is. It will be in the last line you added.
If you are copying code from a book, start by comparing your code to the book’s
code very carefully. Check every character. At the same time, remember that the
book might be wrong, so if you see something that looks like a syntax error, it
might be.
Here are some ways to avoid the most common syntax errors:
(i) Make sure you are not using a Python keyword for a variable name.
(ii) Check that you have a colon at the end of the header of every compound
statement, including for, while, if, and def statements.
(iii) Make sure that any strings in the code have matching quotation marks.
(iv) If you have multiline strings with triple quotes (single or double), make sure
you have terminated the string properly. An unterminated string may cause an
invalid token
error at the end of your program, or it may treat the following
Chia sẻ với bạn bè của bạn: