Lesson 2: __init__ — the constructor and attributes
Last lesson we attached attributes to an object manually, line by line. In this lesson we meet __init__ — a special method that runs automatically every time an object is created and fills in its attributes from the start.
__init__ is an intake form. The moment an object is "born", the form gets filled in — name, age — and the data is stored on it right away.
- constructor __init__
- A special method that runs automatically when a new object is created and initializes its attributes.
- self
- The first parameter of every method — it points at the object itself.
- instance
- Another name for an object created from a specific class.