Functions & Modules
As programs grow, you need reusable building blocks. Functions and modules keep code organized instead of one giant mess.
Learn it
A function packages steps you can reuse with different inputs (parameters) and get a result (return value). Modules group related functions into files you can import.
By the end you’ll be able to
- Write reusable functions
- Organise code into modules
Free resources
- Corey Schafer — Python Tutorial for Beginners (playlist)(opens in a new tab)Start here
Clear episodes on functions, arguments, return, scope
Freeplaylist - Python Docs — Modules (official tutorial)(opens in a new tab)
Official explanation of modules, imports, packages
Free - Kaggle Learn — Python(opens in a new tab)
Hands-on lessons on defining and calling functions
Free7 lessons
Practice
Refactor your earlier scripts so repeated logic lives in functions with clear names and parameters.
Build it — your output
A small reusable module (e.g. `text_utils.py`) with 3–4 functions, imported and used from another file.
Prove it — check yourself
You’re ready to move on when you can honestly say yes to each:
- Can you write a function with parameters and a return value?
- Do you understand local vs global scope?
- Can you import a function from another file?
Do it with AI
Use a free AI tool as your tutor and pair-programmer. Copy a prompt below into Claude, ChatGPT, or Gemini (for building, try Cursor or Copilot).
The habit: Try it yourself first — a little struggle is where the learning actually happens. Then ask for a hint before the answer — never copy blindly.
- Understand itClaude / ChatGPT / Gemini
I'm a beginner learning "Functions & Modules". Explain it in simple terms with a real-world analogy, then ask me ONE question to check my understanding — don't reveal the answer.
- PracticeClaude / ChatGPT / Gemini
Give me 3 short practice problems on "Functions & Modules" (my goal: write reusable functions), from easy to hard. Don't include the solutions yet — I'll try them first, then ask you to check.
- Get unstuckClaude / ChatGPT / Gemini
I'm stuck on this exercise about "Functions & Modules": [paste your attempt here]. Give me ONE small hint to move forward — do NOT give me the full solution.
- Build & reviewCursor / Copilot
Here is my work for a "Functions & Modules" task: [paste your code or answer]. Review it: point out what's wrong and WHY, and suggest improvements — but let me make the fixes myself.
- Prove itClaude / ChatGPT / Gemini
Quiz me on "Functions & Modules". Ask me 5 questions one at a time, wait for my answer each time, then tell me if I'm right and briefly why.