Python默认继承? [英] Python Default Inheritance?

查看:154
本文介绍了Python默认继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在Python中定义一个类,例如:

If I define a class in Python such as:

class AClass:
   __slots__ = ['a', 'b', 'c']

它从哪个类继承?它似乎不继承自 object

Which class does it inherit from? It doesn't seem to inherit from object.

推荐答案

定义一个类,不声明任何特定的父类,该类将成为一个经典类,它的行为有点不同于继承自对象的新式类。有关详情,请参阅此处: http://docs.python.org/release/2.5.2/ ref / node33.html

If you define a class and don't declare any specific parent, the class becomes a "classic class", which behaves a bit differently than "new-style classes" inherited from object. See here for more details: http://docs.python.org/release/2.5.2/ref/node33.html

经典类没有公共根,所以实质上,您的AClass不会继承任何类。

Classic classes don't have a common root, so essentially, your AClass doesn't inherit from any class.

请注意,这是特定于3.0之前的Python版本。在Python 3中,所有类都是新式类,如果没有其他父类声明,则从对象隐式继承。

Note that this is specific to Python versions before 3.0. In Python 3, all classes are new-style classes and inherit implicitly from object, if no other parent is declared.

这篇关于Python默认继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆