【发布时间】:2014-05-07 05:55:04
【问题描述】:
我得到错误:
TypeError: 'int' object is not callable
当我尝试做这样的事情时:
first = Rational()
print(first.numerator())
下面是我的代码:
class Rational:
def __init__(self, numerator=0, denominator=1):
self.numerator = numerator
self.denominator = denominator
def numerator(self):
return self.numerator
def denominator(self):
return self.denominator
def __str__(self):
return str(self.numerator) + "/" + str(self.denominator)
python 似乎认为分子是 int 类型,但我认为我将它作为 Rational 类的属性。我非常困惑。
感谢您的澄清!
【问题讨论】:
-
您不会像在此处粘贴代码那样缩进它吗?我现在不在可以运行 Python 的机器上。
标签: python object int typeerror callable