math.log1p()方法是文库方法的数学模块,其用于获取的自然对数1 + X(以e为底),它接受若干并返回的自然对数1 +号上以e为底。
注意:如果我们提供除数字以外的任何其他内容,该方法将返回TypeError – “ TypeError:需要浮点数”。
math.log1的语法p() 方法:
math.log1p(x)
Parameter(s): x –是要计算其对数的数字。
返回值: float-返回一个浮点值,它是1 + x的自然对数。
示例
Input: x = 21 # 函数调用 print(math.log1p(x)) Output: 3.091042453358316
# python代码演示示例 # math.log1p() method # 导入数学模块 import math # log1p()x = 21 print("Natural logarithm of 1 +", x, " is = ", math.log1p(x)) x = 10.23 print("Natural logarithm of 1 +", x, " is = ", math.log1p(x))
输出结果
Natural logarithm of 1 + 21 is = 3.091042453358316 Natural logarithm of 1 + 10.23 is = 2.418588768750352