类 #
问答 #
class 后面加不加 object 的区别 #
python 3 中已经默认就帮你加载了 object 了(即便你没有写上 object)
python 2.x | python 2.x | python 3.x | python 3.x |
---|---|---|---|
不含 object | 含 object | 不含 object | 含 object |
__doc__ | __doc__ | __doc__ | __doc__ |
__module__ | __module__ | __module__ | __module__ |
__class__ | __class__ | __class__ | |
__delattr__ | __delattr__ | __delattr__ | |
__dict__ | __dict__ | __dict__ | |
__format__ | __format__ | __format__ | |
__getattribute__ | __getattribute__ | __getattribute__ | |
__hash__ | __hash__ | __hash__ | |
__init__ | __init__ | __init__ | |
__new__ | __new__ | __new__ | |
__reduce__ | __reduce__ | __reduce__ | |
__reduce_ex__ | __reduce_ex__ | __reduce_ex__ | |
__repr__ | __repr__ | __repr__ | |
__setattr__ | __setattr__ | __setattr__ | |
__sizeof__ | __sizeof__ | __sizeof__ | |
__str__ | __str__ | __str__ | |
__subclasshook__ | __subclasshook__ | __subclasshook__ | |
__weakref__ | __weakref__ | __weakref__ | |
__dir__ | __dir__ | ||
__eq__ | __eq__ | ||
__ge__ | __ge__ | ||
__gt__ | __gt__ | ||
__le__ | __le__ | ||
__lt__ | __lt__ | ||
__ne__ | __ne__ | ||
__init_subclass__ | __init_subclass__ |
init_subclass #
类方法 __init_subclass__
从 3.6
(whatsnew3.6) 引入,作用是可以在不使用元类的情况下改变子类的行为。严格来说它不属于元类编程,但也能达到编辑其他类的一种手段。
参考:
叶王 © 2013-2024 版权所有。如果本文档对你有所帮助,可以请作者喝饮料。