Write Python. Understand every error.

Open the editor

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.

Try this code in Py-CRAFT

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

Learn the ideas behind it

Other common errors

Share this page: