Programming foundations · L1 · 20 min
Python values and functions
Learn in five minutes
- A function takes an input and returns an output.
- Strings, numbers, lists, and dicts cover the labs.
- A pure function is easier to test than a hidden global.
- Name the unit: tokens, milliseconds, or documents.
- Print the value and the unit together.
Agent code fails when a function both computes and secretly sends data. Split the calculation from the side effect so a test can call the calculation alone.
Visual
A toy token counter
- Define a function that splits on spaces. Label it a toy, not a real tokenizer.
- Assert that 'red fox' returns 2.
- Pass an empty string and expect 0, not a crash.
Quiz
Ecosystem
- Pure function
- Same input, same output, no hidden write.
Sisters: Git, HTTP, JSON, unit tests.
A Python script can later call a local runner or a cloud API with the same JSON shape.
The same notebook becomes the capstone log.
Config
- Write the goal in one sentence.
- Name the input and the allowed output.
- Save the trace next to the result.
Troubleshooting
- The answer looks fluent and is wrong. Check whether a source passage actually contains the claim.
- The loop never stops. Set a step cap and stop when the tool result repeats.
Sources and go deeper
- Python 3 tutorial vendor last checked 2026-10
- Python.org community community last checked 2026-10
- Python (programming language) — Wikipedia wikipedia last checked 2026-10