In Python, __init__ initializes an instance after __new__ creates it and before the instance is returned. It receives the new object as self and assigns attributes such as self.flavor. section 10.6 section 10.8
Use __init__ to:
- Accept arguments passed when the class is called and store them as instance attributes. section 10.6
- Initialize shared parent-class state through super().__init__ rather than duplicating assignments. section 10.16 section 10.26
- Provide defaults or initialize resources, such as a default beverage temperature or an opened file attribute. section 10.8
A subclass delegates initialization
class Person: def __init__(self, name): self.name = name class Employee(Person): def __init__(self, name, id_number): super().__init__(name) self.id_number = id_number Employee('empname', 1) The subclass adds id_number while letting Person initialize name. Without the super call, the parent __init__ does not automatically run merely because the subclass defines its own __init__. section 10.16
When we create an object, __new__ is invoked.
Trace the object-creation sequence: __new__ creates the object, __init__ adds its attributes, and the completed object is returned. section 10.8












