(一)python 中调用 class 中 def 函数格式(新手小白,欢迎大神指点)
class LR(nn.Module):
def __init__(self):
super(LR,self).__init__()
self.linear = nn.Linear(1,1)
def forward(self,x):
out = self.linear(x)
return out
一. class函数没有输入,代码如下
def __init__(self):
def 的调用格式为:
c = LR()
或者
c = LR()
c.forward()
二. class函数有输入或者def函数有输入,调用格式为:
c = LR()
c.forward(x)
开头给出的代码forward有两个输入,一个self一个x,我的理解self就是一种声明,调用def时默认第一位变量是self,因此只需输入self的变量就可以。