What is a metaclass in Python?

PythonServer Side ProgrammingProgramming

A metaclass is a class which has classes as its instances. Like an "ordinary" class defines the behavior of the instances of the class, a metaclass also defines the behavior of its classes and their instances.

Metaclasses are supported by Python. Some programmers consider metaclasses in Python as "solutions waiting or looking for a problem".

There are numerous applications of metaclasses. Few of them are −

  • logging and profiling;

  • interface checking;

  • registering classes at creation time;

  • automatically adding new methods;

  • automatic property creation;

  • proxies etc.

Updated on 15-Jun-2020 11:34:53