基本类
class A(object):
age = 10
def add(self, num):
self.age += num
# type方法
def add(self, num):
self.age += num
A = type('A', (), {'age': 10, 'add': add})
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
C = type('C', (), {'__init__': __init__})
继承类
class A(object):
age = 10
def add(self, num):
self.age += num
class B(A):
def get_age(self):
return self.age
# type方法
def add(self, num):
self.age += num
A = type('A', (), {'age': 10, 'add': add})
B = type('B', (A,), {'get_age': lambda self: self.age})