Review: find the slip (Python core)
Why this matters
The slips that cost the most time raise no error: the code runs and the answer is quietly wrong. The twenty-four lessons before this one each end with practice on their own idea, but none asks you to find a slip among all the ideas at once. That's the job in real code, and in AI code the same ten slips cause the same symptoms: a noisy average loss, results leaking from one run to the next, a layer that never trains. Learn their faces here, on twenty lines, and they get cheaper to spot everywhere.
- Find a slip in a function by working a tiny input by hand and comparing it with what the code should do
- Name ten common Python slips: an accumulator reset in the loop, print for return, a shared list, sort() returning None, a broad except, = for ==, an off-by-one range, text compared as numbers, a missing self., and a list changed while looped over
- Match each Python construct in the core to the NumPy or PyTorch line where you will meet it
def total_spend(rows): for r in rows: total = 0 total += r return total print(total_spend([5, 7]))
The idea: a slip runs, and the answer is wrong
This review rests on the whole Python core: Variables, Loops, Functions, Lists, Errors and exceptions, Classes and Inheritance.
The slips that cost the most time raise no error. Python does what you typed, not what you meant, and the answer comes out wrong and plausible. You can't see one by running the code once. You find it by reading the code the way a reviewer does: pick a tiny input, work it out by hand, and compare it with what the code says. This lesson has ten such slips, one at a time, so that when you meet them in a training script you know their faces.