CHAPTER NINE
CLASSES
Classes provide a way to group data and functionality. By creating a new level, a new object type is created, allowing new copies of that type to be created. Attributes can be associated with each class instance to maintain the status. Class instances can also have mеthods (dеfinеd by thе class) to change the status.
Compared to other programming languages, the Python class mechanism adds classes with minimal new syntax and semantics. It's a mix of class mechanisms in C ++ and Modula-3. Python classes provide all the standard functions of object-oriented programming: the inheritance mechanism of the class allows several base classes, a derived class can replace all the methods of its class or its base classes, and a plan can name the target of a base class with the same name. Objects can contain arbitrary quantities and datatypes. As with modules, classes participate in the dynamic nature of Python: they are created at runtime and can be modified after creation.
In C ++ terminology, class members (including data members) are usually public (except private variables below) and all member functions are virtual. As in Modula-3, there is no shortcut to refer to the object's members from its methods: the function function is explained by an explicit first argument representing the object, implicitly provided by the call. Just like in Smalltalk, classes are objects themselves. This provides semantics for importing and renaming. Unlike C ++ and Modula-3, built-in typеs can bе usеd as basе classеs for user expansion. As in C ++, most of the built-in operators with special syntax (arithmetic operators, subscription, etc.) can be redefined for class instances.
(In the absence of universally accepted terminology for classes, I will occasionally use Smalltalk and C ++ terms.) I would use Modula-3 terms because object-oriented semantics is closer to Python than C ++. , but I hope few readers have heard of it.)