类型错误:';浮动';对象不是可下标的Python 3
我一直收到TypeError:“float”对象不可下标 想知道为什么类型错误:';浮动';对象不是可下标的Python 3,python,typeerror,Python,Typeerror,我一直收到TypeError:“float”对象不可下标 想知道为什么 from math import log class Logarithm(object): def __init__(self, base = 0, number= 0): self.base = float(base) self.number = float(number) the_logarithm = log(self.base[self.number])
from math import log
class Logarithm(object):
def __init__(self, base = 0, number= 0):
self.base = float(base)
self.number = float(number)
the_logarithm = log(self.base[self.number])
def __str__(self):
return 'Your log = {}'.format(the_logarithm)
因此:
log(self.base[self.number])
你想在这里完成什么self.base
是一个浮点数,因此此语句被计算为“base的第th个元素,Python不能这样做。因为:
log(self.base[self.number])
你想在这里完成什么self.base
是一个浮点数,因此这条语句被评估为“base
的第th个元素”,Python不能这样做。Cameron Sparr的回答是正确的
您可能应该重新检查帮助(math.log)
。
是的
这意味着基本参数是可选的(默认为e
)
而不是log(x[base])
Cameron Sparr的答案是正确的
您可能应该重新检查帮助(math.log)
。
是的
这意味着基本参数是可选的(默认为e
)
而不是log(x[base])
同样,它应该是self。对数(在\uuuuu init\uuuuu
和\uu str\uuuuu
中)。此外,它应该是self。对数
(在\uuuu init\uuuuuuu
和中)。