Dunder methods & the data model
P28.data-modelling.02 · Audience: guest, it-ml, language-pro · Prerequisites: Records: class vs dataclass vs namedtuple
Python's data model is the set of dunder (double-underscore) methods that
let your objects plug into the language's syntax and built-ins: ==, <,
hash(), repr(), in, with, and more. Implement them well and your types
feel native; implement them carelessly and you get subtle bugs.
This ladder builds two value objects — a colour and a version — and wires them into equality, hashing, and ordering.
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.
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.
Rung 1 — value equality and hashing
Loading exercise…
Rung 2 — ordering with total_ordering
Loading exercise…
Interview rung — responsible operator overloading (free-form)
Loading exercise…
My notes on this module
Loading your notes...
Where next?
Later in Data Modelling
Go up a level