Properties, descriptors & immutability

P28.data-modelling.03 · Audience: guest, it-ml, language-pro · Prerequisites: Dunder methods & the data model

Real LLM grading for this pageLLM grading (this page):

Attributes don't have to be plain slots. A property turns attribute access into method calls (computed values, validation on set); a descriptor is the reusable machinery behind properties, letting you factor a validation rule out of one class and share it across many; and __slots__ trades per-instance flexibility for memory and a fixed attribute set. Together they are how you make an object correct by construction.

Ask the mentor about this module

Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.

Images, PDF or text. Kept on this device only.
Keeping your files on this device

Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.

Ctrl/Cmd + Enter to send
Rung 1 — write a validating descriptor

Loading exercise…

Rung 2 — __slots__ and a computed property

Loading exercise…

My notes on this module

Loading your notes...

Where next?

Properties, descriptors & immutability — TransformerLab