Apply yesterday's theory with four hands-on Jupyter cells — default parameters, multiple return values, and how imports will restructure your vault.
Day 22 of 80
Read the Cursor Python Guide before opening Jupyter. It's short but useful — it covers how Cursor handles virtual environments, linting, and Python-specific autocomplete. Knowing this makes the Jupyter session smoother.
venv/ folder from Day 21from helpers import tomorrow, Cursor will autocomplete your function namesOpen a new Jupyter notebook in your prompt-vault/ folder (with your venv activated). Run each cell, read the annotations, then experiment by changing values before moving to the next one.
def format_shot(scene_num, description, platform):
"""Format a shot into a display string."""
return f" Scene {scene_num} [{platform}]: {description}"
print(format_shot(1, "Wide establishing shot", "Kling"))
print(format_shot(2, "Close-up hands on club", "Runway"))
print(format_shot(3, "Aerial pull-back", "Veo"))
Line 1: def format_shot(scene_num, description, platform): — the three names in parentheses are parameters. They're placeholders; they get their values when someone calls the function.
Line 2: The triple-quoted string is a docstring. It doesn't run — it documents what the function does. Cursor and Python's help() both display it.
Line 3: return sends the formatted string back to whoever called the function. Without return, this function would print nothing — it would produce None.
Lines 5–7: Each call passes three arguments — the real values that fill in the parameters. Notice how the same function produces three differently formatted lines. That's the point of functions: write once, use many times with different data.
Expected output:
Scene 1 [Kling]: Wide establishing shot Scene 2 [Runway]: Close-up hands on club Scene 3 [Veo]: Aerial pull-back
Try this: Remove the return and assign result = format_shot(1, "test", "Kling"). Print result. You'll see None. That's what Python returns when a function has no return statement.
def generate_filename(platform, shot_type="general", extension="json"):
clean_platform = platform.lower().replace(" ", "_")
clean_type = shot_type.lower().replace(" ", "_")
return f"{clean_platform}_{clean_type}.{extension}"
print(generate_filename("Kling"))
print(generate_filename("Runway", "aerial"))
print(generate_filename("Veo", "tracking", "txt"))
Line 1: shot_type="general" and extension="json" are default parameters. If the caller doesn't supply these, the defaults kick in. Required parameters (like platform) must always come before defaulted ones.
Line 2: Chaining .lower().replace() is common Python style — clean the string in one readable line. If platform is "Kling AI", this produces "kling_ai".
Line 4: Returns a filename string built from all three cleaned values.
Lines 6–8: Three calls with different numbers of arguments. When you skip a defaulted parameter, Python uses the default silently — no error, no fuss.
Expected output:
kling_general.json runway_aerial.json veo_tracking.txt
Try this: Call generate_filename("Runway", extension="csv") — using the parameter name to skip shot_type entirely. Python calls these keyword arguments.
def analyze_shots(shots):
total = len(shots)
platforms = {}
for s in shots:
p = s["platform"]
platforms[p] = platforms.get(p, 0) + 1
most_common = max(platforms, key=platforms.get)
return total, platforms, most_common
shots = [
{"platform": "Kling", "shot": "wide"},
{"platform": "Kling", "shot": "close"},
{"platform": "Runway", "shot": "aerial"},
]
total, breakdown, top = analyze_shots(shots)
print(f"Total: {total}")
print(f"Breakdown: {breakdown}")
print(f"Most used: {top}")
Line 2: len(shots) counts all shots — this becomes the first return value.
Lines 3–6: Builds a frequency dictionary. platforms.get(p, 0) is the safe way to read a dictionary key — if the key doesn't exist yet, return 0 instead of crashing. Then add 1 for this shot.
Line 7: max(platforms, key=platforms.get) finds the key (platform name) with the highest value (count). The key= argument tells max how to compare — compare by the dictionary's values, not the keys themselves.
Line 8: return total, platforms, most_common — Python quietly wraps these three values into a tuple and returns it as one object.
Line 15: total, breakdown, top = analyze_shots(shots) — tuple unpacking. Python splits the returned tuple into three separate variables in one line. This is clean, professional Python style.
Expected output:
Total: 3
Breakdown: {'Kling': 2, 'Runway': 1}
Most used: Kling
Try this: Add a fourth shot for Veo and re-run. See how the breakdown and most_common update automatically — no code changes needed.
# These functions live in helpers.py in your real project.
# Here we're defining them in the notebook to test the logic.
def clean_text(text):
return text.strip().lower()
def validate_platform(platform, valid=["kling", "runway", "veo"]):
cleaned = clean_text(platform)
if cleaned in valid:
return cleaned.capitalize()
return None
# From your main script: from helpers import clean_text, validate_platform
print(validate_platform(" KLING "))
print(validate_platform("Pika"))
print(validate_platform("runway"))
Lines 4–5: clean_text() strips surrounding whitespace and lowercases the string. Two method calls chained together — one line does both jobs.
Line 7: validate_platform() takes a raw user-typed platform string. The valid= default parameter defines the accepted list — you can override it by passing your own list.
Line 8: Calls clean_text() from inside validate_platform(). Functions can call other functions — this is how you build layered, readable logic.
Lines 9–10: If the cleaned platform is in the valid list, return it with a capital first letter (so "kling" becomes "Kling" — consistent for display).
Line 11: If not valid, return None. The caller can check if validate_platform(...) is None: to detect bad input.
Line 13: This commented line shows the real import syntax you'll use in vault.py tomorrow: from helpers import clean_text, validate_platform. Python looks for helpers.py in the same folder and imports exactly those names.
Expected output:
Kling None Runway
Try this: Create a new file helpers.py in your vault folder, paste clean_text and validate_platform into it, then open a Python shell in that folder and run from helpers import validate_platform. It works — that's tomorrow's foundation.
You can write functions that accept parameters (with or without defaults), return single or multiple values, and call other functions. You understand how Python's import system works for both built-in modules and your own files. Tomorrow you use all of this to restructure your entire Prompt Vault into a professional multi-file project.
from helpers import ... will work in tomorrow's buildTomorrow is a full build day. You'll take your Week 3–4 code and reorganize it into a proper multi-file project: helpers.py for reusable functions, vault.py as the main script, and requirements.txt to document your dependencies. It's the same logic — just organized so that professionals can read and extend it.