Syntax Error
SyntaxError: invalid syntax. print statement must be followed by a colon (:)
What This Error Means
This error occurs when Python encounters a syntax that doesn't conform to its rules. In this case, the print statement is missing a colon at the end.
Why It Happens
Python requires a colon (:) at the end of a print statement when it's used as part of a control structure, such as if-else or for loops. Without it, Python gets confused and raises a SyntaxError.
How to Fix It
- 1To fix this error, simply add a colon (:) at the end of the print statement. For example, if you have `print('Hello World')`, change it to `print('Hello World'):`. Alternatively, if the print statement is inside a control structure, make sure it's properly indented.
Example Code Solution
❌ Before (problematic code)
Python
if x > 5:
print('x is greater than 5')
print('x is greater than 5')✅ After (fixed code)
Python
if x > 5:
print('x is greater than 5'):Fix for SyntaxError: invalid syntax. print statement must be followed by a colon (:)
Browse Related Clusters
Related PYTHON Errors
Related PYTHON Blog Articles
Have a different error? Get an instant explanation.
Explain Another Error