动态生成类的可使用type()
一.先查看普通创建类的方法
class A():
def __init__(self):
print('A初始化')
class B(A):
def __init__(self):
super().__init__()
a=A()
print(type(A))
b=B()
执行的结果为:
二.使用type 创建类
C=type('C',(object,),class_dict)
print(type(C))
c=C()
print(c.x)
执行结果为:
三.使用type 创建类并继承