Code Clinic - The Build - Book 7: Classes & Objects
In Python your data and your logic have been living apart. A class puts them back together, and this book builds one from nothing. The first distinction carries everything else: a class is a blueprint, an object is a thing stamped out from it. Then __init__ and self, the two pieces of syntax that confuse almost everyone at this stage, explained slowly and with the reason behind each. You create objects and give each one its own data, so a patient record carries an MRN and a name that belong to it alone. Methods come next, functions that live inside the class and work on the object's own data, so a record can describe itself. Then methods that take parameters, which is how an object acts on information you hand it at the moment you call it. A chapter on many independent objects proves the point that matters most, that changing one object leaves the rest untouched. The book finishes with a patient registry, a working collection of record objects that each know how to check themselves in.
Seventeen A4 pages, in full colour. Written in short sentences and plain English, for readers whose first language is not English and clearer for everyone else because of it.
Every code example in this book was run before the page was printed, so the output you read is the output you get. Instant PDF download. By M.R. Sterling.