我想写一个类方法,它接受3个关键字参数。我以前使用过关键字参数,但好像在我的类内部无法使用。以下是代码:
def gamesplayed(self, team = None, startyear = self._firstseason,
endyear = self._lastseason):
totalGames = 0
for i in self._seasons:
if((i.getTeam() == team or team == "null") and
i.getYear() >= startyear and i.getYear() <= endyear):
totalGames += i .getGames()
return totalGames
产生错误:
NameError: name 'self' is not defined
如果我去掉关键字参数,将它们变为简单的位置参数,它就可以正常工作。因此,我不确定我的问题出在哪里。感谢您提前的帮助。