Lesson 1 · Python Foundation
Choosing between paths.
You know this idea thoroughly by now: IF something is true, THEN do this.
You drew it as decision trees in Chapter 4. You snapped it together in Scratch. You wrote it in JavaScript.
Python's version is the cleanest of the lot:
if age >= 13:
print("You can join")
else:
print("Too young")
No brackets around the condition, no curly braces. Just a colon — and then something Python takes very seriously indeed.
This is the one genuinely new idea in Python, and it matters.
In most languages, indentation is politeness. In Python it's grammar. The indented lines after a colon are the ones that belong to the if:
if score > 50:
print("You passed") # inside the if
print("Well done") # also inside
print("Program finished") # NOT inside — runs always
Move that last line four spaces right and it only prints when the score is above 50. The spacing changes what the program does.
Use four spaces, consistently. Your editor will help, but the responsibility is yours.
6 more parts in this lesson
Walkthroughs, code labs, mini-games and the checkpoint quiz unlock when you buy the course.