Syntax is the set of symbols, words, and rules that make a program valid in a language. It includes punctuation, brackets, indentation, and the order of expressions. AI assistants can generate much of this structure, but generated code still needs checking. section 1.3 section 1.4
When writing Python, syntax determines details such as:
- Which brackets to use: [, (, or {. section 1.4
- Where indentation, parentheses, commas, and colons are required. section 1.4 section 2.6.1
- How expressions and values are ordered. section 1.4
A small syntax mistake
This working program calculates a square’s area: side = 5; area = side * side; print("Side length:", side, "Square area is:", area). Omitting the comma in the print call produces a SyntaxError. Copilot can help produce correct punctuation, but testing remains necessary. section 2.5
File "c:\Users\Leo\Copilot\first_program.py", line 7
print("Side length:" side, " Square area is:", area)
^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
Inspect the concrete Python error caused by a missing comma and see how syntax errors identify invalid program structure. section 2.5


