Menu
A Note on Syntax and Code Blocks
When writing code, using correct syntax is critical. Even a small typo, like a missing parenthesis bracket or an extra
comma, can cause a syntax error and the code won't execute at all. If your code results in an error or an exception,
pay close attention to syntax and watch out for minor mistakes. A single wrong character could take hours to
identify in long code so it is important to be mindful of syntax when writing code.
Common syntax errors:
Misspellings
Incorrect indentations
Missing or incorrect key characters:
Bracket types - ( curved ), [ square ], { curly }
Quote types - "straight-double" or 'straight-single', “curly-double” or ‘curly-single’
Block introduction characters, like colons - :
Data type mismatches
Missing, incorrectly used, or misplaced Python reserved words
Using the wrong case (uppercase/lowercase) - Python is a case-sensitive language
If your syntax is correct, but the script has unexpected behavior or output, this may be due to a semantic problem.
Syntax is like the vocabulary, grammar, spelling, and punctuation of code. Semantics are the meaning and logic of
coded statements. It is possible to have syntactically correct code that runs successfully, but doesn't do what we
want it to do.
Common semantic errors:
Creating functional code, but getting unintentional output
Poor logic structures in the design of the code
When working with the code blocks in exercises for this course, be mindful of syntax and semantic (logic) errors,
along with the overall result of your code. Just because you fixed an error doesn't mean that the code will have the
desired effect when it runs! Once you’ve fixed an error in your code, don't forget to click Run to check your work.
Mark as completed
Like Dislike Report an issue