本文摘自php中文网,作者爱喝马黛茶的安东尼,侵删。
log() 返回 x 的自然对数。math.log(x) 就相当于数学中的ln(x),x>0,求底数为e的对数,e = 2.718281828459;math.log10(x) 就相当于数学中的lg(x),x>0,求底数为10的对数。可以通过log(x[, base])来设置底数,如 log(x, 10) 表示以10为底的对数。
语法
以下是 log() 方法的语法:
1 2 | import math
math.log(x[, base])
|
注意:log()是不能直接访问的,需要导入 math 模块,通过静态对象调用该方法。
参数
x -- 数值表达式。base -- 可选,底数,默认为 e。
相关推荐:《Python视频教程》
返回值
返回 x 的自然对数,x>0。
实例
以下展示了使用 log() 方法的实例:
1 2 3 4 5 6 7 8 | #!/usr/bin/python
# -*- coding: UTF-8 -*-
import math # 导入 math 模块
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)# 设置底数
print "math.log(10,2) : " , math.log(10,2)
|
以上实例运行后输出结果为:
1 2 3 4 5 | math.log(100.12) : 4.60636946656
math.log(100.72) : 4.61234438974
math.log(119L) : 4.77912349311
math.log(math.pi) : 1.14472988585
math.log(10,2) : 3.32192809489
|
以上就是python中对数函数怎么表示的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python可变参数*args和**kwargs用法实例小结
Python实现shell sed替换简单的功能
Python实现读取json文件到excel表
Python如何配置清华镜像源
Python接单平台有哪些
什么是Python函数
在电脑上怎么下载Python
Python中单下划线和双下划线有什么区别
Python装饰器-限制函数调用次数的方法(10s调用一次)
什么是Python类属性?类的私有属性是什么?(实例解析)
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python中对数函数怎么表示