Python数字log()
方法返回x
的自然对数(x > 0)。
语法
以下是log()
方法的语法 -
import math
math.log( x )
注意 - 此方法不能直接访问,需要导入
math
模块,然后使用math
静态对象调用此函数。
参数
- x - 这是一个数字表达式。
返回值
- 该方法返回
x
的自然对数(x > 0
)。
示例
以下示例显示了log()
方法的用法。
#!/usr/bin/python3
import math # This will import math module
print ("math.log(100.12) : ", math.log(100.12))
print ("math.log(100.72) : ", math.log(100.72))
print ("math.log(math.pi) : ", math.log(math.pi))
当运行上述程序时,它会产生以下结果 -
math.log(100.12) : 4.6063694665635735
math.log(100.72) : 4.612344389736092
math.log(math.pi) : 1.1447298858494002