Python Syntax
Prerequisites: Your first Python program
Python's defining syntax rule: indentation defines blocks, instead of
curly braces { } like many other languages use.
if True:
print("This line is inside the if block")
print("So is this one")
print("This line is not — it always runs")
A line ending in : (like if True:) opens a new block; every line
indented underneath it belongs to that block. The standard indent is 4
spaces.
Common mistakes
- Mixing tabs and spaces for indentation — Python will raise an error rather than guess. Configure your editor to insert spaces when you press Tab.
- Inconsistent indentation (3 spaces on one line, 4 on the next) inside the same block.