Show class relation between type and object:
issubclass(type,object)
True
issubclass(object,type)
False
It is clear that type
derived from object
,object
is the father class of type
,type
is the son class
of object
.
isinstance(type,object)
True
isinstance(object,type)
True
How to understand that type
is the instance of object
and vice versa ?
isinstance(object, classinfo)
Return
True
if the object argument is an instance of the classinfo argument, or of a (direct, indirect or virtual) subclass thereof.
https://docs.python.org/3.9/library/functions.html?highlight=isinstance#isinstance
type
is an instance of object
object
is a base for all classesObjects are Python’s abstraction for data. All data in a Python program is represented by objects or by relations between objects.
https://docs.python.org/3.9/reference/datamodel.html#types
object
is a base for all classes.
https://docs.python.org/3.9/library/functions.html?highlight=object#object
type
inherits from object
(https://docs.python.org/3.9/library/functions.html?highlight=object#type) so type
is both a subclass and also an instance of object
using the isinstance
description.object
is an instance of type
object
is a type object. In other words, object
is of type, type
Type Objects
Type objects represent the various object types. An object’s type is accessed by the built-in functiontype()
https://docs.python.org/3.9/library/stdtypes.html?highlight=subclass#type-objects
type(object) # returns type
type(type) # returns type
object.__class__ # returns type
type.__class__ # returns type
Which helps us understand how isInstance(object, type)
will return True
.
An intuitive way to think about this is that the object
object is of type type
but object
is not a subclass of type
because it doesn't inherit from type