Lesson 7: Class vs instance attributes
So far every attribute lived on the object itself. But some data is shared by all objects of a class — and it has a different home: the class body. We'll learn to tell a class attribute from an instance attribute, and how Python looks them up.
A class attribute is like the sign on the classroom door — one sign, everyone sees it; an instance attribute is like each student's notebook — everyone has their own.
- class attribute
- A variable defined directly in the class body, shared by every object created from it.
- instance attribute
- An attribute stored on a specific object via self — each object has its own copy.