Data Model
say it: “DAY-tuh MOD-ul” /ˈdeɪtə ˈmɑdəl/
The dunder methods that let your objects work with len(), +, for and more.
What is Python's data model?
Python's data model is the set of dunder methods that let your objects work with built-in features: len(), +, ==, for loops and square brackets.
class Money:
def __init__(self, cents):
self.cents = cents
def __add__(self, other):
return Money(self.cents + other.cents)
def __eq__(self, other):
return self.cents == other.cents
print(Money(150) + Money(50) == Money(200)) # True
Level: Master · More Python terms at this level
Updated