带有Python示例的math.log()方法
Pythonmath.log()方法
math.log()方法是数学模块的库方法,用于将给定数字的自然对数以e为底(默认情况下)。它接受数字和一个底数(可选),并返回自然对数。
注意:如果我们提供除数字以外的任何其他内容,该方法将返回TypeError–“TypeError:需要浮点数”。
它的语法math.log()方法:
math.log(x [, base])
Parameter(s):
x–是要计算其对数的数字。
base–是一个可选参数,用于定义对数的任何特定底数。
返回值:float-它返回一个浮点值,它是数字x的自然或底数对数。
示例
Input:
x = 21
#函数调用
print(math.log(x))
Output:
3.044522437723423Python代码演示示例math.log()方法
#python代码演示示例
# math.log() method
#导入数学模块
import math
# log() with 1 parameter
x = 21
print("Natural logarithm of ", x, " is = ", math.log(x))
# log() with 2 parameters
x = 21
base = 5
print("logarithm of ", x, " with base ", base, " is = ", math.log(x, base))输出结果
Natural logarithm of 21 is = 3.044522437723423 logarithm of 21 with base 5 is = 1.8916681496081529
热门推荐
10 医院探望朋友祝福语简短
11 毕业祝福语简短女朋友
12 春节虎年爸妈祝福语简短
13 儿童毕业祝福语 简短6
14 开工仪式横幅祝福语简短
15 孩子日常祝福语大全简短
16 清晨寄语诗句祝福语简短
17 结婚送亲认亲祝福语简短
18 虎年喝酒拜年祝福语简短