Error guide · SyntaxError
SyntaxError: invalid syntax
The code breaks Python's grammar rules, so Python cannot even start running it.
Example
marks = 72 if marks >= 40 print("Pass")
What Python says
SyntaxError: expected ':'
As printed by Python 3.12. Other versions may word it slightly differently.
Why it happens
Python reads the whole program before running it. A missing colon, bracket or quote makes the grammar invalid. The error is reported where Python got confused, which is often at, or just after, the real mistake.
How to fix it
marks = 72 if marks >= 40: print("Pass")
Output: Pass
Tips
- Lines starting
if,elif,else,for,while,defandclassend with a colon:. - Every
(,[,{and quote needs a matching closing one. - Use
==to compare; a single=stores a value. - If the reported line looks fine, look at the line above it.