python log() 函数获取自然对数

时间:2016-08-16
python log()函数用于获取x的自然对数。log()是不能直接访问的,需要导入 math 模块,通过静态对象调用该方法,本文章向大家介绍python log() 函数的使用方法和实例,需要的朋友可以参考一下。

python log()函数介绍

log() 方法返回x的自然对数。

语法:

import math
math.log( x )

注:此功能是不能直接访问的,所以我们需要导入的数学模块,然后我们需要调用这个函数,用数学的静态对象。

参数: 

  1. X:这是一个数值表达式。

返回值: x的自然对数为x> 0

python log()实例

#!/usr/bin/python
import math   # This will import math module
#  http://www.manongjc.com/article/1362.html 
print "math.log(100.12) : ", math.log(100.12)
print "math.log(100.72) : ", math.log(100.72)
print "math.log(119L) : ", math.log(119L)
print "math.log(math.pi) : ", math.log(math.pi)

这将产生以下结果:

math.log(100.12) :  4.60636946656
math.log(100.72) :  4.61234438974
math.log(119L) :  4.77912349311
math.log(math.pi) :  1.14472988585