number of ways firstthe class can explicitly specify its metaclass by either setting _metaclass_ class variable (python )or supplying the metaclass keyword argument in the tuple of base classes (python class foo__metaclass__ type in python use the syntax class foo(metaclass=typeif no metaclass is explicitly specifiedthe class statement examines the first entry in the tuple of base classes (if anyin this casethe metaclass is the same as the type of the first base class thereforewhen you write class foo(object)pass foo will be the same type of class as object if no base classes are specifiedthe class statement checks for the existence of global variable called _metaclass_ if this variable is foundit will be used to create classes if you set this variableit will control how classes are created when simple class statement is used here' an example_ _metaclass_ type class foopass finallyif no _metaclass_ value can be found anywherepython uses the default metaclass in python this defaults to types classtypewhich is known as an oldstyle class this kind of classdeprecated since python corresponds to the original implementation of classes in python although these classes are still supportedthey should be avoided in new code and are not covered further here in python the default metaclass is simply type(the primary use of metaclasses is in frameworks that want to assert more control over the definition of user-defined objects when custom metaclass is definedit typically inherits from type(and reimplements methods such as _init_ (or _new_ (here is an example of metaclass that forces all methods to have documentation stringclass docmeta(type)def _init_ (self,name,bases,dict)for keyvalue in dict items()skip special and private methods if key startswith(" ")continue skip anything not callable if not hasattr(value," _call_ ")continue check for doc-string if not getattr(value," _doc_ ")raise typeerror("% must have docstringkeytype _init_ (self,name,bases,dictin this metaclassthe _init_ (method has been written to inspect the contents of the class dictionary it scans the dictionary looking for methods and checking to see whether they all have documentation strings if nota typeerror exception is generated otherwisethe default implementation of type _init_ (is called to initialize the class to use this metaclassa class needs to explicitly select it the most common technique for doing this is to first define base class such as the followingclass documented_ _metaclass_ docmeta in python use the syntax class documented(metaclass=docmetaf lib fl ff