3.3. Special method names¶
原文的内容比较冗长,检索起来不便,本文是对其的一个总结,可以作为shortcut。
3.3.1. Basic customization¶
名称 | |||
---|---|---|---|
object.__new__(cls[, ...]) ¶ |
|||
object.__init__(self[, ...]) ¶ |
|||
object.__del__(self) ¶ |
|||
object.__repr__(self) ¶ |
|||
object.__str__(self) ¶ |
|||
object.__bytes__(self) ¶ |
|||
object.__format__(self, format_spec) ¶ |
|||
object.__lt__(self, other) ¶object.__le__(self, other) ¶object.__eq__(self, other) ¶object.__ne__(self, other) ¶object.__gt__(self, other) ¶object.__ge__(self, other) ¶ |
|||
object.__hash__(self) ¶ |
|||
object.__bool__(self) ¶ |
3.3.2. Customizing attribute access¶
3.3.3. Customizing class creation¶
3.3.4. Customizing instance and subclass checks¶
3.3.5. Emulating generic types¶
3.3.6. Emulating callable objects¶
3.3.7. Emulating container types¶
名称 | 网络资源 | 例子 | |
---|---|---|---|
object.__contains__(self, item) ¶ |
Called to implement membership test operators(如in ). |
- Functionality of Python in vs. __contains__ - https://www.oreilly.com/library/view/python-in-a/0596001886/re16.html |
3.3.8. Emulating numeric types¶
这是最最简单的。