Can you explain the concept of metaclasses in Python and provide an example of how they can be used to customize class behavior?
Metaclasses in Python allow you to customize the creation and behavior of classes. They are often used to enforce coding standards or add functionality to classes. Here's a basic example:
class Meta(type):
def __new__(cls, name, bases, dct):
dct['custom_attribute'] = 42
return super().__new__(cls, name, bases, dct)
class MyClass(metaclass=Meta):
pass
print(MyClass.custom_attribute) # Output: 42