3.2. Syntax RulesΒΆ

At their core, programming languages are collections of rules that allow us to tell a computer what to do. Actions like Repeat ____ 25 times, Prompt the user for a password, or Display text on the screen can be done with any language. However, each one uses a different approach to complete the tasks.

Syntax refers to the rules and structure of a language. For example, in English, a sentence must begin with a capital letter and end with proper punctuation.

Python and other languages can only run a program if it is syntactically correct. Even tiny mistakes will cause a program to crash. While humans are good at overlooking minor errors, computers cannot do the same.

For example, the following phrases are badly written, but humans can still understand them. We might need to read them out loud several times, but we will eventually get the point.

  1. Peas on urth

  2. Whirled wor too

  3. I awlyas thaut slpeling was ipmorantt

Other examples include vanity license plates:

Plate

Meaning

KC ROKS

Kansas City (or Casey?) Rocks

4EVERL8

Every parent trying to get their kids to afternoon practice

Computers cannot overlook mistakes like humans. Any syntax errors, no matter how small, will prevent the code from running. Instead of trying to work around the issue, the program will immediately crash and generate error messages.