python math.exp()方法,计算e的幂次方

math.exp()方法

python math模块的exp()方法,可以用于求取底数为自然常数e的幂次方运算,相当于pow()中的第一个参数指定为math.e,或者将math.e进行“**”幂次方运算符的运算。


exp()语法

exp(x, /)

python源码中对exp()方法的介绍:

Return e raised to the power of x.

参数

参数描述
x必须参数,而且是real number,指定幂的次方

返回值

Python浮点型float数值。


math.exp()实例代码

下方实例对比了math.exp()方法、python内置函数pow()和运算符“**”的用法:

>>> import math
>>> math.exp(2)
7.38905609893065
>>> pow(math.e,2)
7.3890560989306495
>>> math.e**2
7.3890560989306495
>>> math.exp('a') #参数must be real number
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be real number, not str

全栈后端 / Python库 :









Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.