Common causes
- A missing colon at the end of an if, for, while, def, or class statement
- Mismatched parentheses, brackets, or quotes — an opening one was never closed
- Using Python 3 syntax in Python 2 (or vice versa), such as print 'hello' instead of print('hello')
- A typo like = instead of == in a condition, or an extra/missing comma
How to fix it
- Look at the line the error points to AND the line immediately before it
- Check that every opening bracket (, [, { has a matching closing one
- Make sure every if/for/while/def/class line ends with a colon :
- Run python --version to confirm you're using the right Python version
Example
File "app.py", line 5
if x == 1
^
SyntaxError: invalid syntaxA missing colon at the end of an if statement
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
