A question: Are these “re-defined” dunder methods for matching the input data types or is this a coincidence?
In the UserGroup
example, we put in dunders like __iter__
, __len__
, __contains__
to users
that are designed to make a list work and, the corresponding parameters in can_edit
and can_delete
are lists. So I am guessing that we know beforehand we were going to put lists in and thus we write these list dunders in. Is this correct? If this is correct, then I am puzzled again — isn’t the idea of redefining dunder methods making them do something different from what it originally does? And since it is a list itself, why do we need to define these operations again?
This is really a complicated part for me. Thanks in advance!