First page Back Continue Last page Overview Graphics

type()

If we apply the function type to classes like „list“ or „str“ itself, the result is the class „type“.

So, we can see, that classes are created from „type“. The fact that classes are instances of the class „type“ allows us to program metaclasses: We can create classes, which inherit from the class „type“.

Instead of only one argument, „type“ can be called with three parameters:

type(classname, superclasses, attributes_dict)

"classname" is a string defining the class name.

"superclasses" is a list or tuple with the superclasses of our class.

attributes_dict“ is a dictionary, functioning as the namespace of our class.