Skip to content

Pedagogy: add classes mini-notebook under 06_python_advanced/ #395

@kwlee2025cpp

Description

@kwlee2025cpp

Goal

NMISP touches classes very briefly inside 00_introduction/20_python_review.ipynb but doesn't dedicate space to teaching them. Several later-chapter topics would read more naturally with a class-based API (e.g. an ODESolver with step() / solve() methods, a Polynomial with arithmetic, a Vector2D for linear-algebra intro). Without a focused classes notebook, those expressions can't be introduced cleanly later.

Scope

Create 06_python_advanced/40_classes.ipynb covering:

  • Defining a class, __init__, attributes
  • Methods, including a couple of __dunder__ examples (__repr__, __add__)
  • Basic inheritance (one parent → one child) with one example
  • Brief note on when to use a class vs. a function (don't oversell OOP)

Worked example: Polynomial (coefficients list, evaluate at x, add two polynomials, derivative). One exercise: extend with __mul__ or evaluate at an array of xs.

Optional second example: Vector2D with __add__, __sub__, dot, __repr__. Foreshadows 40_linear_algebra_1/.

Why

  • Without classes, later chapters either avoid OOP entirely (limiting expressiveness) or introduce it inline (interrupting the numerical topic).
  • A short, dedicated notebook is the cheapest way to unblock that future flexibility.
  • Counter-balance: keep it small. Don't try to teach everything about Python OOP; one example, one exercise, move on.

Acceptance

  • Notebook executes end-to-end.
  • Polynomial class has at least __init__, evaluate(x), __add__, __repr__.
  • One exercise with a solution cell.
  • Notebook stays short (~25–40 cells); resist scope creep.

Metadata

Metadata

Assignees

No one assigned

    Labels

    pedagogyNotebook content / teaching changes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions