2013-05-06 72 views
0

我不断收到类型错误:“浮动”对象未标化的 想知道为什么类型错误:“浮动”对象未标化的Python 3

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) 
+0

也,它应该是'self.the_logarithm'(均在'__init__'和'__str__' )。 – nvlass 2013-05-06 23:09:04

回答

2

正因为如此:

log(self.base[self.number]) 

你是什么试图在这里完成? self.base是一个浮点数,因此该语句被评估为“base”的number th元素,Python不能这样做。

2

Cameron Sparr的回答是正确的。

您应该重新检查help(math.log)。 它是

log(x[, base]) -> the logarithm of x to the given base. 

这意味着碱参数是可选的(默认为e) 和不log(x[base])

相关问题