Skip to content
BENIBIX Learn

Syntax Error

Development🧩 Programming ConceptsErrors

Also known as SyntaxError, Parse Error

Code that breaks the grammar rules of its language. Not one line of it runs.

Think of it like

Think of it like a sentence with no full stop and half a word. The reader gives up before the end.

Example

Jack types if score > 10 and forgets the colon in Python. The program will not start until he adds it.

Why it matters

They are the easiest kind to fix. The computer tells you where they are.

Definition

A syntax error is code that breaks the grammar rules of its language. A missing bracket, a stray comma or a misspelled keyword are common causes. The computer cannot even read the program, so not one line runs. The message points to the line where it got confused. The real mistake is often on that line or the one just above it.

Example code

python
>>> if score > 10
  File "<stdin>", line 1
    if score > 10
                 ^
SyntaxError: expected ':'
The colon is missing. Python says just what it wanted.

Common mistake

Only looking at the line in the message. The missing bracket is often on the line before.

Key takeaways

  1. 1
    Nothing runs. The program stops before the first line.
  2. 2
    Easy to find. The message points to the spot.
  3. 3
    Look one line up. The cause is often just above.

Compare

Learn it properly