预计阅读本页时间:-
喜欢这本书吗?请把本站加入广告屏蔽插件白名单
无弹窗/漂浮窗等广告形式,不影响阅读
Chapter Summary
That’s as many overloading examples as we have space for here. Most of the other operator overloading methods work similarly to the ones we’ve explored, and all are just hooks for intercepting built-in type operations; some overloading methods, for example, have unique argument lists or return values. We’ll see a few others in action later in the book:
- Chapter 33 uses the __enter__ and __exit__ with statement context manager methods.
- Chapter 37 uses the __get__ and __set__ class descriptor fetch/set methods.
- Chapter 39 uses the __new__ object creation method in the context of metaclasses.
In addition, some of the methods we’ve studied here, such as __call__ and __str__, will be employed by later examples in this book. For complete coverage, though, I’ll defer to other documentation sources—see Python’s standard language manual or reference books for details on additional overloading methods.
In the next chapter, we leave the realm of class mechanics behind to explore common design patterns—the ways that classes are commonly used and combined to optimize code reuse. Before you read on, though, take a moment to work though the chapter quiz below to review the concepts we’ve covered.