A constructor method is a special method that runs when an object is created. In Python, it is written as __init__ inside a class and usually sets the object's initial data attributes. section 31.2 section 31.7
class Circle(object):
def __init__(self):
self.radius = 0
This small Circle class gives each new object its own radius, initially set to zero through self.radius. section 31.2
The parameter self refers to the particular object being initialized. Writing self.radius creates an attribute that belongs to that object, so different objects can hold different values. section 31.2
Passing starting values
A Rectangle constructor can accept length and width: Rectangle(2, 4). Inside __init__, self.length = length and self.width = width preserve those values as attributes. Omitting a required value, as in Rectangle(2), raises a TypeError because width is missing. section 31.5
Remember these points:
- Define __init__ inside a class to describe initial object setup. section 31.2
- Use self.attribute to create or set data that persists for the object's lifetime. section 31.5
- Supply every required constructor argument when creating an object. section 31.5












