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

前端 未结 8 1342
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 may use super(Foo, self) where Foo is a class and self is the instance.

    super(type[, object-or-type])

    Return a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by getattr() except that the type itself is skipped.

    And in Python 3.x you can simply use super() inside a class without any parameters.

提交回复
热议问题