#

问答 #

class 后面加不加 object 的区别 #

python 3 中已经默认就帮你加载了 object 了(即便你没有写上 object)

python 2.xpython 2.xpython 3.xpython 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) 引入,作用是可以在不使用元类的情况下改变子类的行为。严格来说它不属于元类编程,但也能达到编辑其他类的一种手段。

参考:


本文访问量

本站总访问量

本站总访客数