![](/img/trans.png)
[英]What is the relationship between Python built-in modules and built-in types/functions?
[英]What is the relationship between Python 3 built-in types?
据我所知,类关系在Python 3中有点像这样:
object
的子类 type
的实例 每个类都是由type
类或另一个从type
派生的元类创建的。 因此,每个类都是type
(包括type
!)的实例。每个类将为isinstance(cls, type)
返回True
。
在Python 3中,每个类也是object
的子类。 每个类或实例将为isinstance(cls_or_instance, object)
返回True
。
元类是一个特例。 一个元类是从type
派生的,因此每个元类将为issubclass(metaclass, type)
和isinstance(metaclass, type)
返回True
。
类型对象本身就是一个对象。 请注意,尽管python的继承模型与其他OO语言不同,但它很大程度上取决于鸭子的类型而不是继承。
请注意, type(x)
返回对象的类型, type(object)
返回<class 'type'>
意味着object
的类型(所有对象都具有的type
)就是type
(所有类型的类型是), type
本身就是类型,所以它的类型又是type
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.