Python SyntaxError: expected ':'
A plain-words explanation of this Python message: what it means, the usual causes, and the steps that fix it.
The messageSyntaxError: expected ':'
Make the error yourself
Run with Python 3.14.10. This is the smallest example we could find that shows it.
Python program (main.py)
number = 7
if number > 5
print("big")Output (the real message)
File "main.py", line 2
if number > 5
^
SyntaxError: expected ':'Why it happens
The statements if, elif, else, for, while, def, class, try, except and with must end with a colon. The colon tells Python that an indented block follows. The traceback shows the line and puts a caret under the place where Python noticed the problem, which is the end of the line where the colon is missing.
How to fix it
- Go to the line shown in the message and add
:at the end of it. - Check the lines above too, because a missing bracket on an earlier line can make Python complain later.
- Make sure the next line is indented.
The corrected version
Python program (main.py)
number = 7
if number > 5:
print("big")Output (the corrected version)
bigHow to avoid it
An editor with syntax colouring shows a missing colon as soon as you press Enter. When you copy code from the web, check that the colons were not lost.
Questions
Why does Python sometimes report the error on the next line?
Python can only tell something is wrong when it reaches a place where the rule is broken. An unclosed bracket on line 3 may be reported on line 4.
This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.