The Builder unrolls a massive blue scroll. "This is the Blueprint," he explains.
"In other lands, builders use braces {} or keywords to mark the beginning and end of a room.
But here in Pythonia, we use Indentation."
He points to a messy pile of bricks. "Without proper alignment, everything collapses."
The Law of Alignment
In Python, whitespace at the beginning of a line is not just for looks—it determines the structure of your code.
Statements that belong together (like the commands inside an if) must be indented by the same amount of spaces.
The standard is 4 spaces.
if True:
print("This will cause an IndentationError!")
if True:
print("This is safe inside the block.")
print("This is also inside.")
print("This is outside, back on the main level.")
The code on the right is trying to build a structure, but the indentation is all wrong.
Fix the IndentationError by adding spaces (Tab key) to push the code blocks inside their respective if statements.
The nested if (checking materials_ready) should be inside the first if.
And the print statements about building should be inside the second if.
If you mix tabs and spaces, the Python interpreter will get confused and might throw an error. Stick to spaces (or let the editor convert Tab to spaces)!
Advanced TipsWant more? Click to expandClick to collapse
Python's use of indentation to mark blocks is often called the "off-side rule".
Most other programming languages (like C, Java, JavaScript) use curly braces { } to define blocks,
and indentation is just for readability. In Python, readability is the syntax.