Syntax

The grammar rules for how Python code must be written.

Syntax is the set of grammar rules every Python program must follow: a colon after an if, for, or def line; consistent indentation for the block underneath; and matching quotes and brackets. Break a rule and Python reports a SyntaxError and refuses to run the file at all — nothing executes until it's fixed.

Example
# Correct syntax: a colon, then an indented block
if 3 > 2:
    print("valid Python")

# Missing the colon would raise, before anything runs:
#   SyntaxError: expected ':'
Output
valid Python

Where this shows up in real Python

Syntax governs every line you write. A syntax error stops the program before it runs at all, unlike a runtime error that happens mid-execution.

Official documentation: Python Tutorial: Syntax Errors

Related lessons

Related terms