Module 2
Indentation
Why spaces at the start of a line matter.
Python cares about spaces
In Python, the spaces at the beginning of a line are not just for readability. They tell Python which lines belong together. This is called indentation.
Python
score = 85
if score >= 70:
print("Pass")
print("Good job")
print("Done")→ Pass
Good job
Done
The two indented lines belong to the if block. They run only when the condition is true. The last print is not indented, so it always runs.
A common mistake
Mixing tabs and spaces, or using the wrong number of spaces, causes an IndentationError. Use four spaces for each level of indentation.
Why does Python use indentation?