Lesson 06 · Python
Object-Oriented Design: Classes & Objects
Model real nouns with your own types: class syntax, __init__ and self, attributes vs methods, __str__ and __repr__, and the judgment to know when a class is overkill.
Prerequisites: Python Foundations: Errors, Modules & Files
Learning objectives
By the end of this lesson, you will be able to:
- Explain what problem classes solve that plain dicts and functions do not
- Write classes with __init__, self, instance attributes and methods
- Implement __str__ and __repr__ so objects print usefully in both worlds
- Read and write code that creates, uses and validates objects
- Choose honestly when a plain dict and functions beat a class