类,实例和type 的关系, 类的继承关系

版权声明:转载 或者复制请标注来源 https://blog.csdn.net/qq_34979346/article/details/83120232

1.类,实例,type 的关系
类一共有两种 , 第一是内置的 比如 str, int, list 第二种就是 自定义的, 比如 Class Student: pass

比如 : int 1 通过 type(1) 可以得到 1 就是 int 类 的一个实例 对象, 同样 通过 type(int) 可以得出, int 是type 类的实例对象 type, 通过type(object)同样可以得出 object 是type的实例,

type 和type 之间可以互相转换,也就是 type 是type 的实例, 得出 type 可以创造 一切 对象 包括 自身 和 object

这就是 实例, 类 ,type 的关系。
2.类的继承关系
类的继承关系中, Parent: pass , Child(Parent): pass
通过 Child.bases 可以得出 他的继承是 Parent, 继续 用 Parent.bases 可以得出 继承的 是object, 同样 str.bases_ 也是继承 的 object , 包括type 也是继承object ,他是 类的鼻祖

猜你喜欢

转载自blog.csdn.net/qq_34979346/article/details/83120232