What is the difference between old style and new style classes in Python?

前端 未结 8 1306
Happy的楠姐
Happy的楠姐 2020-11-21 04:48

What is the difference between old style and new style classes in Python? When should I use one or the other?

8条回答
  •  梦如初夏
    2020-11-21 05:08

    New-style classes inherit from object and must be written as such in Python 2.2 onwards (i.e. class Classname(object): instead of class Classname:). The core change is to unify types and classes, and the nice side-effect of this is that it allows you to inherit from built-in types.

    Read descrintro for more details.

提交回复
热议问题