Python is such an easy language to learn but it is a very difficult one to master. One of the basics of the language is the Data Model. What is a data model and when do I use it? The Data Model is a that formalizes the building blocks of the Python language itself, such as sequences, functions, iterators, coroutines, and so on. It is used all the time as you cannot write relevant code without it. set of interfaces Pythonic How do I use it? The short answer is we in these interfaces. implement the methods When we want our objects to support and interact with fundamental language constructs like: Collections Iteration Operator overloading Asynchronous programming and managed contexts Special Methods You probably came across this method and others written with leading and trailing double underscores, this is a serving as a Constructor for your Object. __init__ Special Method are meant to be called by the Python Interpreter and not by us, we just implement them if needed, and we use the syntactic sugar offered to us like with this Special Methods __add__ that gets called by the “+” operator: var = 'hello' var2 = ' world' # this is how we should write print(var + var2) # hello world # this is not how we should write, meant to be called by Python Interpreter print(var.__add__(var2)) # hello world A Python object should also provide usable of itself, one used for , and another for . These are and string representations debugging and logging presentation to end users Special Methods __repr__ __str__ class Point: def __init__(self, x, y): self.x = x self.y = y def __repr__(self): return f"Point({self.x}, {self.y})" def __str__(self): # Default implementation, to change depending on user needs return self.__repr__() >>> p = Point(1, 2) >>> p Point(1, 2) >>> p.x = 4 >>> p Point(4, 2) There are more than 100 , most of which implement , , and . Here’s a to the full list. Special Methods Arithmetic Bitwise Comparison Operators link By , your objects can , enabling the expressive coding style the community considers Pythonic. implementing Special Methods behave like the built-in types The Collections API The Collection API is an Integral Module of the Python Data Model, this API offers us interfaces for these types: , formalizing the interface of built-ins like and Sequence list str , implemented by , , etc. Mapping dict collections.defaultdict , the interface of the and built-in types. Set set, frozenset All the classes in the diagram are or Abstract Base Classes. Each of the top ABCs has a single special method. ABCs : The Collection ABC unifies the three essential interfaces that every collection should implement to support , , and other forms of iteration Iterable for unpacking to support the built-in function Sized len to support the operator Container in Keep in mind that it is , for example, any class that implements satisfies the interface. not required to inherit from any of these ABCs __len__ Sized Also published (in full) here. Further Reading The “Data Model” chapter of is the canonical source for the subject of this chapter and much of this book. The Python Language Reference , 3rd ed. by Alex Martelli, Anna Ravenscroft, and Steve Holden (O’Reilly) has excellent coverage of the data model. Python in a Nutshell . Python Essential Reference