Loading topic
__init__ and regular methods, and that you know how print(), f-strings and lists behave. It covers the two methods that control how an object turns into text, and the __format__ hook behind f-string format specs.3 min read__init__ methods. It also assumes you know that isinstance checks a value's type and that str, int and tuple are immutable. By the end you will know what Python does when you write Cls(...). You will also know when __init__ is not e4 min read__init__ and regular methods, and that you know how set and dict are used. You should also have read the earlier chapter on __repr__, since the examples use it to show results.4 min reada < b means for your own classes, and how functools.total_ordering reduces the amount of code you write. It assumes you have read the chapters on __eq__ and __hash__ and on returning NotImplemented. It also assumes you are comfortable with tuples 5 min readbool(), if obj:, int(), float() and indexing. It assumes you can write a class with __init__ and regular methods, and that you know __len__ from the data model overview. The __bool__ and __len__ methods decide truthiness. __int__, `__f3 min reada + b, it does not add anything itself. It asks the left operand's type to do the work by calling a.__add__(b). If your class defines __add__, your code runs. This chapter covers the binary arithmetic methods, how Python picks which one to call, and the errors that come u4 min read__init__ and __repr__. It also assumes you have seen __add__ and __mul__ on a small class such as a vector. Here you will learn how Python picks which operand handles a binary operator. You will also learn why unsupported operand types should p4 min read__init__ and __repr__. It also assumes you have seen how + maps to __add__ in the earlier chapters. Here you will implement the one-operand operators -x, +x and ~x, and the built-in abs(x).4 min read__init__ and __repr__. It also assumes you know __add__ and NotImplemented from the arithmetic and reflected-operator chapters, and that you know the difference between mutable objects (lists, dicts) and immutable ones (tuples, strings, numbers4 min readlist, dict and tuple behave. A container is an object that holds other objects and answers questions such as "how many?", "what is at position 2?" and "is this inside?". You can make your own4 min readfor loops and built-in containers like list work. It also assumes you have seen special methods such as __len__ and __getitem__ from the container chapter. Here you will learn the two-method protocol behind every `4 min readobj(...).5 min readtry/finally, and have used with open(...). It builds on the earlier chapters, where syntax maps to methods looked up on an object's type.3 min read__dict__, and have read the earlier chapters on special methods. By the end you will know when Python calls __getattr__, how it differs from __getattribute__, and how to avoid the infin4 min read@property. It also assumes you have read the earlier chapters on __getattr__ and dynamic attribute access.4 min read__repr__, __eq__ and __hash__, the arithmetic and reflected operators, the container and iteration protocols, and __getattr__. The question now is when using them helps4 min read