Code with the error

temperature = 25
if temperature > 20
    print("Warm")

Error message (Python 3.12, last line)

SyntaxError: expected ':'

Corrected code

temperature = 25
if temperature > 20:
    print("Warm")

Output

Warm

Common causes

  • No colon after if, else, for, while or def.
  • A bracket or a quote is opened and never closed.
  • One = where a comparison needs ==.
  • A reserved word such as class or for used as a variable name.

Practise in the course

Lesson: Conditions

Frequently asked questions

Why does the message point at the wrong line?

Python notices the problem only when it cannot continue, so the real mistake may sit one line higher.

Why is nothing printed before the error?

Python reads the whole program before running it. With a syntax error no line is executed.