Creating our own classes of objects
The two lists of data values that HQ asked us to get—cheese consumption and W75 deaths—form two objects that are very similar. They seem to be two instances of the same class of things.
In this case, the class of things seems to have annual statistics. They're collections with a consistent structure of a year and a measurement. Both these annual statistics objects have a common set of operations. Indeed, the operations are pretty tightly bound to the measurement, and they are not at all bound to the year number.
Our collection of statistical functions is not very tightly bound to our data at all.
We can improve the binding between data structure and processing through a class definition. If we define the general ...
Get Python for Secret Agents now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.