What is the purpose of subclassing the class “object” in Python?

前端 未结 6 1974
太阳男子
太阳男子 2020-11-30 05:15

All the Python built-ins are subclasses of object and I come across many user-defined classes which are too. Why? What is the purpose of the class object<

6条回答
  •  失恋的感觉
    2020-11-30 06:00

    The short version is that classic classes, which didn't need a superclass, had limitations that couldn't be worked around without breaking a lot of old code. So they created the concept of new-style classes which subclass from object, and now you can do cool things like define properties, and subclassing dict is no longer an exercise in pain and strange bugs.

    The details are in section 3.3 of the Python docs: New-style and classic classes.

提交回复
热议问题