我定义了一个函数,它是
from math import *
def func(x):
return log(e,x)
错误很短很清楚,你知道为什么python不能评估吗
func(1)
,等于ln(1)?
编辑:由于我是新来的,我发布了一个愚蠢的问题,很抱歉,但现在我已经处理了
@mike_z的建议是正确的,
我有一段向后的论点,换句话说,我想到了函数
math.log(a,b)
或log(a,b)
(取决于你如何提高数学模)
就好像a表示基数,b表示对数要计算的另一个操作数
但真正的方法是,上面句子的倒数是正确的,
坦克你们所有人!
这是log
函数的定义。如评论中所述,您的基数不能为1
。
def log(x, base=None): # real signature unknown; restored from __doc__
"""
log(x[, base])
Return the logarithm of x to the given base.
If the base not specified, returns the natural logarithm (base e) of x.
"""
pass
您可以看到以下操作:-
>>> import math
>>>
>>> def func(x):
...
... return math.log(10, x)
...
>>> print func(1)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "<input>", line 3, in func
ZeroDivisionError: float division by zero
>>> print func(2)
3.32192809489
>>> print func(3)
2.09590327429
>>> print func(4)
1.66096404744
>>>