Phase 1 — Core Foundations
Syntax & Indentation
Python's biggest rule coming from JS/TS — indentation defines blocks
This is probably the first thing you need to get used to, coming from JS/TS.
In JavaScript, { } marks a block:
if (age >= 18) {
console.log('Adult');
}In Python, a : starts a block, and indentation defines what belongs inside it. There
are no curly braces.
if age >= 18:
print("Adult")Multiple lines can belong to the same block:
if age >= 18:
print("Adult")
print("Can vote")
print("Done")Here's how that breaks down:
if block
├── print("Adult")
└── print("Can vote")
outside block
└── print("Done")Python usually uses 4 spaces for indentation.
Wrong vs. right
# ❌ Wrong — missing indentation
if age >= 18:
print("Adult")# ❌ Also wrong — inconsistent indentation
if age >= 18:
print("Adult")
print("Can vote")# ✅ Correct
if age >= 18:
print("Adult")
print("Can vote")Quick comparison
| JS/TS | Python |
|---|---|
{ } | indentation |
( ) around condition | not required |
; | not required |