【发布时间】:2018-05-04 11:35:23
【问题描述】:
我正在逐字阅读python官方文档。
在 3.3.特殊方法名3.3.1. Basic customization
在object基本自定义下确实指定了16个特殊方法,我收集如下:
In [47]: bc =['__new__', '__init__', '__del__', '__repr__', '__str__', '__bytes__',
'__format__', '__eq__', '__le__', '__lt__', '__eq__',
'__ne__', '__ge__', '__gt__', '__hash__', '__bool__']
In [48]: len(bc)
Out[48]: 16
问题是其中三个不是object的有效属性
In [50]: for attr in bc:
...: if hasattr(object,attr):
...: pass
...: else:
...: print(attr)
...:
__del__
__bytes__
__bool__
对象是所有类的基础。 2. Built-in Functions — Python 3.6.3 documentation
它没有递归基类。
为类'object'定义的__del__、__bytes__、__bool__的方法在哪里?
【问题讨论】:
标签: python python-3.x class object methods