Foundations · #0 of 11

Welcome + Python Mental Model

How Python executes and why indentation matters

Why it matters

A clean mental model prevents 80% of beginner bugs and makes problem-solving faster.

The idea

Think of Python as a smart calculator plus a notebook. Expressions create values; names point to those values; statements do work.

The interpreter reads your file top-to-bottom. Indentation isn't decoration — it's syntax. Two spaces in, two spaces out: that's a block.

Try it

A name is a label stuck on a value. Re-binding x doesn't change 5, it just points the label elsewhere.

x = 5
print("x is", x)
x = "now I'm a string"
print("x is", x, "of type", type(x).__name__)
not loaded

Blocks are defined by indentation. Mix tabs and spaces and Python will rightfully refuse to run.

for i in range(3):
  if i % 2 == 0:
      print(i, "even")
  else:
      print(i, "odd")
not loaded

Quick check

Mini drills

Do's and don'ts

Common mistakes

Key takeaways