Python Syntax Practice
Python syntax gets easier when you practice the small rules repeatedly. Use these examples to review indentation, expressions, strings, lists, and function structure.
Syntax practice is about making the small rules automatic. Python depends on readable structure, so indentation, colons, variable names, and function definitions all carry meaning.
Use each question as a quick rule check. When an answer is wrong, name the exact syntax rule before moving on so the mistake becomes easier to spot next time.
- Assignment, comments, and function definitions
- Colons after control-flow statements
- Indentation as part of program structure
Example practice questions
Try these samples, then continue into the Python Practice Labfor guided browser-based practice.
Which line correctly assigns the number 5 to a variable named score?
Answer: score = 5
Which character starts a Python comment?
Answer: #
What keyword starts a function definition?
Answer: def
What is missing from if score > 10?
Answer: A colon at the end: if score > 10:
Which syntax creates a list of three numbers?
Answer: [1, 2, 3]
Which keyword repeats over items in a list?
Answer: for
What does Python use to mark blocks of code?
Answer: Indentation