✍️ Syntax

5th Grade 💻 Coding

Syntax is the “grammar” of a programming language: the rules for how to write a correct instruction — where the parentheses, quotation marks, colons and spaces go.

Free · US Letter · no sign-up
Google Classroom Save to Pinterest Email me

Every programming language has its own syntax. In Python, an if line ends with a colon and the lines inside it are indented. In JavaScript you put the condition in parentheses and the instructions in curly braces. Same idea — different syntax.

People can understand a sentence even with spelling mistakes, but the computer isn’t forgiving: one missing parenthesis and it can’t understand the whole line. That’s why code editors color different parts in different colors and mark syntax errors even before you run the program. Block languages like Scratch have almost no syntax errors, because blocks that don’t fit simply won’t snap together.

For example

  • In Python, print("Hi") is correct, and print "Hi" — without parentheses — is a syntax error in today’s Python.
  • In English, “The dog chased the ball” follows the rules of grammar, and “Ball the chased dog the” doesn’t. Code has rules like that too.

📌 Remember: Syntax = how you write it. Logic = what you mean.

Quick quiz

  1. What is syntax in programming?

  2. Why does Scratch have almost no syntax errors?

  3. Do all languages have the same syntax?

🔎 Ask Thinkapedia another question