Reputation: 1
I keep getting TypeError: 'float' object is not subscriptable wondering why
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)
Upvotes: 0
Views: 4549
Reputation: 3981
Because of this:
log(self.base[self.number])
What are you trying to accomplish here? self.base
is a float so this statement is being evaluated as "the number
th element of base
", which Python can't do.
Upvotes: 2
Reputation: 685
Cameron Sparr's answer is correct.
You should probably re-check the help(math.log)
.
It is
log(x[, base]) -> the logarithm of x to the given base.
meaning that the base argument is optional (defaults to e
)
and not log(x[base])
Upvotes: 2