|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Python |
Python objects are instances of classes. Each instance (object) in a Python program has its own namespace.
A class definition creates a class object (type classobj). The names in the namespace of a class object are called class attributes . Function definitions inside of a class statement create methods. Methods are functions that process instances.
When an object is created, its namespace inherits all the names in the namespace of the class of that object. The names in the namespace of an instance are called the instance attributes of that instance.
A method is a function created in a class definition. The first argument of a method always refers to the instance being processed. By convention, the first argument of a method is always named self. Therefore, the attributes of self are instance attributes.