我一直收到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])
def __str__(self):
return 'Your log = {}'.format(the_logarithm)发布于 2013-05-07 07:06:08
因此:
log(self.base[self.number])你想在这里完成什么?self.base是一个浮点数,所以这条语句的计算结果是“base的第number个元素”,这是Python所不能做到的。
发布于 2013-05-07 07:12:45
卡梅隆·斯帕尔的答案是正确的。
您可能应该重新检查help(math.log)。它是
log(x[, base]) -> the logarithm of x to the given base.这意味着基本参数是可选的(缺省为e),而不是log(x[base])
https://stackoverflow.com/questions/16408695
复制相似问题