|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Python |
The __init__ method of a class is special.
The purpose of a __init__ method is to initialize an object.
The __init__ method is invoked whenever a new instance of a class is created.
The __init__ method of the Complex class
is defined in Program
.
Consider the following statement:
i = Complex(0, 1)The effect of this statement is equivalent to the following sequence of statements:
c = object.__new__(Complex) Complex.__init__(c, 0, 1)The __new__ method of the built-in object class is called to create a new object instance. Then __init__ method of the Complex class is called to initialize that instance.