object is the most base type of all objects in Python. That means everything in Python is an
isinstance(anything, object) is always true):
And, all values in Python have a type:
From the examples above, we can easily see that the class is the type of instances created. Or, in other words, the class is a callable that creates instances.
However, classes are values too; in fact, classes are ordinary objects in Python that can be passed around just like any other objects. This characteristic earned itself the nickname: first-class objects. Please note that classes in C++ are not first-class objects, but the instances of classes are. This really makes the statement - everything in Python is an object - even more true.
Since classes are values too, or, in other words, classes are instances of some type(s), what is the
‘type’ of classes (let’s focus only on
builtin classes now …)? In the begining of this post, I
object is the most base type of all objects - does that mean the type of classes
object? - Let’s find out:
What’s going on here? From above, it tells us several things:
builtinclasses are instances of class
typeis its own class; this class creates new
typeobject is still an instance of
typeis a child of
This requires some thought (a brain-twister!), but basically the take-away is: all Python
builtin classes are instances of
type itself and
object. In other
words, the ‘base’ type of class/type system in Python is class
type is a special and important class, because it is used when defining classes (creating
class instances). It is actually a Python MetaClass, which means a
class of classes or a type of types. More about this in Part II.