Python preflight¶
This page is the on-ramp for learners who have not programmed before. It is a compact vocabulary check, not a hidden prerequisite course.
Decision: can you trace the small Python structures used in lesson 01?
Output: a hand trace that names values, types, iteration, and one failure.
Frame¶
Python stores values under names:
time = 0.45
label = "kinetic energy"
samples = [0.10, 0.18, 0.19]
row = {"t": 0.45, "kinetic_energy": 0.186}
time is a floating-point number, label is text, samples is an ordered
list, and row maps explicit field names to values. Predict the value and type
of each expression before running it:
Predict¶
What should fail here, and why is the failure useful?
Read an error from the final line upwards: the final line names the immediate failure; the traceback shows how execution reached it.
Build¶
A function names one transformation:
A loop repeats a transformation while preserving visible state:
Lesson 01 later compresses the same idea into a generator expression:
Read it as the ordinary loop below:
Verify¶
Without running code, trace this program on paper:
rows = [{"energy": "0.10"}, {"energy": "0.19"}]
energies = [float(row["energy"]) for row in rows]
assert max(energies) == 0.19
Record the value and type of row, row["energy"], energies, and
max(energies). Then change one string to "missing" and predict the first
failure.
Reflect¶
You are ready for lesson 01 if you can explain:
- what a name refers to;
- how a list differs from a dictionary;
- what indexing and a function call do;
- how a loop and a comprehension repeat work;
- where to begin reading a traceback.
Keep the syntax map open while learning. Looking up notation is normal; hiding an unexamined assumption is the actual problem.