为什么exp ** 2会产生错误“**不支持的操作数类型”?

时间:2017-09-05 00:15:50

标签: python typeerror

为什么会产生错误?

>>> from math import exp
>>> exp**2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for ** or pow(): 'builtin_function_or_method' and 'int'

1 个答案:

答案 0 :(得分:2)

exp**必须是expe**(在后一种情况下,from math import e)。 math.exp不是常量e的名称,而是指数函数。

>>> exp(2)
7.38905609893065
>>> from math import e
>>> e**2
7.3890560989306495