Python中type和object类的关系
2021-07-19 22:16
1091 查看
源码分析
class type(object): """ type(object_or_name, bases, dict) type(object) -> the object's type type(name, bases, dict) -> a new type """ pass class object: """ The base class of the class hierarchy. When called, it accepts no arguments and returns a new featureless instance that has no instance attributes and cannot be given any. """ pass
可以简单的看得,object是type的父类,那么type是继承object基类的。
简单的输出
print(type(type)) print(type(object)) # 输出结果 # <class 'type'> # <class 'type'>
那么说明type其实是类型的顶端,而object是类的顶端。
总结
- type类是数据类型的顶端,我们除了object的type也是type。
- type类的父类是object,那么说明object类是继承类的顶端。
- 构造数据类型需要使用到type类,那么如果我们想创建自己的自定义类就可以继承type实现创建自己的自定义类型,同时可以使用很多魔方方法来实现自己的类型的内容的封装。
- 以后机会详细讲解一下type元类的使用,以及常用的场景。
相关文章推荐
- python面向对象-理清object与type的关系
- python面向对象-理清object与type的关系
- python面向对象-理清object与type的关系
- python--type,object,元类,__new__,__init__关系
- python中type、class、object的关系
- Python 的 type 和 object 之间是怎么一种关系?
- Python 的 type 和 object 之间是怎么一种关系?
- python中 type object class之间的关系
- python面向对象-理清object与type的关系
- Python 的 type 和 object 之间是怎么一种关系?
- python Flask :TypeError: 'dict' object is not callable
- python变量与地址的关系
- Mybatis中javaType和jdbcType对应关系
- Python中super()或object.__new__报TypeError: object.__new__() takes no arguments错误的解决方案
- python中的type()和isinstance()
- python-opencv-matlab图像处理接口关系
- TypeError: Could not build a TypeSpec for...;Can‘t convert non-rectangular Python sequenceto tensor
- Python中类、实例和类方法、静态方法、实例方法的关系
- Python常见的错误类型及其继承关系
- python错误类型继承关系