每天学一点新知识

Python中type和object类的关系

2021-07-19  本文已影响0人  FANDX

源码分析

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是类的顶端。

总结

上一篇 下一篇

猜你喜欢

热点阅读