class Duration(object):
def __init__(self, minutes, seconds):
self.minutes = minutes
self.seconds = seconds
def get_minutes(self):
return self.minutes
def get_seconds(self):
return self.seconds
def total_seconds(self): #This part is wrong
return 60*(self.get_minutes()) + self.get_seconds()
这是我的代码。对象方向 - 返回值
我想找到总秒数(Duration(3, 30)).total_seconds)
应该给我210
但现在我得到这个<bound method Duration.total_seconds of <__main__.Duration object at 0x0211AD90>>
如何获得210
?
** ** total_seconds是一种方法,你不打电话。您正在获得参考资料。 – tuxuday
删除'get'方法,没有理由,因为你已经可以很好地访问'seconds'和'minutes'。 – kindall