Track 11 · Lesson 2 of 12
__init__ and attributes
How __init__ and self set up each new object, with default values, derived attributes and validation.
You will be able to
- Explain what self refers to and why every method receives it
- Write an __init__ method with required and default parameters
- Store cleaned or derived values as instance attributes
- Reject invalid arguments in __init__ by raising ValueError or TypeError
- Avoid sharing one mutable default value between objects
Included with a Formula Quest membership
It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.
View Formula Quest memberships
Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.