By Example: Classes and Object-Oriented Programming in Python
A class is a data structure than can contain both variables and functions within a single entity. In Python, such classes are first class objects - and by extension, once we create an instance of a class we say that we have created an instance object. Beyond this basic practical standpoint, object-oriented programming (OOP) embodies three defining principles: (1) encapsulation, (2) inheritance, and (3) polymorphism - and by utilising these design methods we can vastly reduce the amount of code duplication in our programmes, as well creating code that is conceptually easier to understand. In this article I'll start with a practical example that demostrates all three principles of OOP and then work through the script, line by line, to discuss how Python implements classes and object-oriented programming.