Write Python. Understand every error.

Open the editor

Error guide · SyntaxError

SyntaxError: expected ':'

A line that starts a block is missing the colon at the end.

Example

for i in range(3)
    print(i)

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

Lines that begin with if, elif, else, for, while, def or try open a block, and each must end with a colon. The colon tells Python that the indented lines below belong to it. Python reports the error on the line that needs the colon.

How to fix it

for i in range(3):
    print(i)

Output: 0 ⏎ 1 ⏎ 2

Tips

Learn the ideas behind it

Other common errors

Share this page: