Syntax Basics
Python syntax will feel weird for exactly one day — then it clicks. Five ideas, one reel.
▶ Watch this reelWhat you'll learn
- Dynamic typing
- Indentation & blocks
- f-strings & formatting
- None & truthiness
- Operators & ranges
Remember this
- Variables are name tags — untyped, movable, runtime-checked
- Indentation IS the block structure — 4 spaces, no braces
- f-strings interpolate anything; falsy = None/0/empty; use
is None
Dynamic typing
x = 5— no type declaration. Variables are names bound to objects.- Rebinding to another type is legal; errors appear at runtime (type hints + mypy fix this — Reel PY-08).
Indentation & blocks
- Whitespace is syntax: indent = enter block, dedent = exit block.
- 4 spaces per level (PEP 8); set the editor to convert tabs.
- Everything in a block must be indented — even single statements.
f-strings
f"Total: {price:.2f}" # format spec inside braces
f"{n:,}" # thousands separators
f"{name.upper()} ok" # any expression
None & truthiness
None= absence of a value (like null). Check withis None.
| Falsy | Truthy |
|---|---|
None, False, 0, "", [], {}, () | everything else |
Operators
==value equality ·isidentity (same object) ·inmembership.range(5)→ lazy sequence 0..4;list(range(5))materializes it.for i in range(n):replaces C-style index loops in most cases.
Code: Syntax basics in 20 lines
# Dynamic typing — name tags, not declarations
price = 19.99
label = "pro"
price = label # legal! the tag moves to a string
# Indentation is the block
if price == "pro":
print("Pro plan")
print(" unlimited reels")
print("always runs") # dedented → outside the if
# f-strings: interpolation + formatting
rows = 1_234_567
print(f"Imported {rows:,} rows in {0.847:.2f}s")
# Truthiness
items = []
if not items: # same as: if len(items) == 0
print("empty list is falsy")
if price is None:
pass # explicit None check with `is`
# in + range
for i in range(3): # 0, 1, 2
if "pro" in label:
print(f" step {i + 1} of 3")