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
Goal
NMISP touches classes very briefly inside
00_introduction/20_python_review.ipynbbut doesn't dedicate space to teaching them. Several later-chapter topics would read more naturally with a class-based API (e.g. anODESolverwithstep()/solve()methods, aPolynomialwith arithmetic, aVector2Dfor linear-algebra intro). Without a focused classes notebook, those expressions can't be introduced cleanly later.Scope
Create
06_python_advanced/40_classes.ipynbcovering:__init__, attributes__dunder__examples (__repr__,__add__)Worked example:
Polynomial(coefficients list, evaluate atx, add two polynomials, derivative). One exercise: extend with__mul__or evaluate at an array ofxs.Optional second example:
Vector2Dwith__add__,__sub__,dot,__repr__. Foreshadows40_linear_algebra_1/.Why
Acceptance
__init__,evaluate(x),__add__,__repr__.