Sobes.tech
Junior — Middle

What built-in mechanism in Python allows you to determine or create a new metaclass?

sobes.tech AI

Answer from AI

In Python, the metaclass keyword is used in class definitions to specify or create a new metaclass. A metaclass is a class that creates other classes.

Example of creating a custom metaclass:

class Meta(type):
    def __new__(cls, name, bases, dct):
        print(f'Creating class {name}')
        return super().__new__(cls, name, bases, dct)

class MyClass(metaclass=Meta):
    pass

# When creating MyClass, the __new__ method of the Meta metaclass will be called