1.经典类的写法: 父类名称.__init__(self,参数1,参数2,...)
2. 新式类的写法:super(子类,self).__init__(参数1,参数2,....)
class A():
def __init__(self, init_age):
super().__init__() #构造函数的继承
print('我年龄是:', init_age)
self.age = init_age
def __call__(self, added_age):
print('__call__被调用了')
res = self.forward(added_age)
return res
def forward(self, input_):
print('forward 函数被调用了')
return input_ + self.age
print('要开始了。。。。')
a = A(10) #这应该是实例化
input_param = a(2)
print("我现在的年龄是:", input_param)
##############################################
######### 输 出 ################
要开始了。。。。
我年龄是: 10
__call__被调用了
forward 函数被调用了
我现在的年龄是: 12