The concept
Python: a programming language that reads close to plain English. Most AI libraries and agent SDKs offer a Python version.
The six ideas:
- Variable: a labeled box holding a value. total = 6
- List: an ordered collection. ["Billing", "Card", "Fraud"]
- Dictionary (dict): a lookup of key → value. {"Billing": 3}. Same shape as JSON (Day 26).
- Loop: do something for each item. for row in rows:
- Function: a named, reusable recipe. def count_by_category(path):
- Package: someone else's code you reuse. csv comes built in; others you add with pip install.
Walkthrough: counting tickets per category
tickets.csv has a header row "id,category" and, say, 6 tickets: 101 Billing, 102 Card, 103 Billing, 104 Fraud, 105 Card, 106 Billing.
The script (count.py):
import csv
def count_by_category(path):
counts = {}
for row in csv.DictReader(open(path)):
counts[row["category"]] = counts.get(row["category"], 0) + 1
return counts
print(count_by_category("tickets.csv"))
What happens, line by line:
- import csv loads the built-in CSV package.
- def creates a function that takes a file path.
- counts = {} starts an empty dict.
- The loop reads one row at a time as a small dict, e.g. {"id": "101", "category": "Billing"}.
- counts.get(…, 0) + 1 means "current count, or 0 if new, plus one."
- Output: {'Billing': 3, 'Card': 2, 'Fraud': 1}
Indentation matters: 4 spaces mark what sits inside the function and the loop.
Why this matters for agents: an agent's tool (Day 37) is often exactly this, a small Python function the model can ask your app to run.
Where you see it at work
- Banking: complaints per product.
- Retail: returns per reason code.
- Healthcare: referrals per department.
- Business analysis: profiling a data extract before writing requirements.
Try it today (10–15 min)
1. Install Python from https://www.python.org/downloads/ (on Windows, the docs recommend the Python install manager).
2. In the VS Code terminal (Day 47), run: python --version (on a Mac: python3 --version).
3. In your learn-ai folder, create tickets.csv with the header and the 6 rows above.
4. Create count.py, paste the script, run: python count.py
5. Add a row "107,Fraud" and run it again.
Official tutorial: https://docs.python.org/3/tutorial/
In one sentence
Variables, lists, dicts, loops, functions and packages are enough to read data and build the small tools agents rely on.
