1.1: 🧭 Syntax

Topic

1.1: 🧭 Syntax

Topic Progress:

Let’s talk about Syntax!

  1. Python is a language where we type instructions for the computer instead of dragging blocks like in Scratch.
  2. Syntax means the specific characters we type in Python. Syntax errors happen when we make mistakes like misspelling or forgetting brackets.
  3. Syntax errors are a problem because they confuse the computer and it can’t understand what we want it to do.
  4. Luckily, the computer gives us error messages to help us find and fix the mistakes. Always read the error messages.
  5. Before we start, let’s understand the term “string.” In coding, a string is a word or sentence in quotation marks, not yarn.
  6. The name “string” comes from the idea that words and sentences are just a bunch of characters placed together.
  7. Python uses indentation (spaces or tabs) to understand what is inside and outside of certain instructions like if-statements and loops.
  8. Indentation helps Python know which lines of code are part of an instruction and which are not.
  9. It’s important not to randomly add spaces in front of lines because it changes the meaning of the code.
  10. Indentation is important for understanding complex Python programs and it also makes the code easier to read.

Remember, it’s important to type instructions correctly and pay attention to the error messages. Understanding indentation will help you write better code in the future.Regenerate response

Indentation

print("This will print no matter what.")

if(x == 1):
print("This will print if x is one.")

print("This will also print no matter what.")

Do you see how the line just below the if statement is tabbed in?

This tells python that line is what we want as part of the if statement and anything not tabbed in is outside of the if statement.

With a text language like python you need to be precise with your syntax, a bracket or full stop in the wrong place could create errors in your program and it will not compile. Python is also case sensitive this means Word, woRd, and WoRd do not mean the same thing in python. This is useful to know when you are creating variables in a later lesson.

@

Not recently active