Summary
In this chapter, we've seen the basics of defining a class and using objects of that class. We've looked at how we create the methods that define the behavior of a class. The internal state of the class is the result of the various methods: in Python we don't formally declare instance variables. We generally rely in the __init__()
method to provide the initial or default values for the object's state.
We've looked at the way Python resolves attribute and method names by searching the object, the class, and then the superclasses. The method resolution order is based on the order the classes are presented in the initial class
statement.
The @properties
decorator can be used to create methods that have the same syntax as an attribute. This can help clarify otherwise complex algorithms. We've also looked at the @staticmethod
decorator, which is used to create methods that belong to the class as a whole and are independent of any specific instance of the class...