Python log() 函数
log() 返回 x 的自然对数。
语法
以下是 log() 方法的语法:
import math
math.log(x[, base])
注意:log()不能直接访问,需要导入math模块,通过静态对象调用该方法。
参数
x — 数值表达式。base — 可选,底数,默认为 e。
返回值
返回 x 的自然对数,x>0。
实例
以下展示了使用 log() 方法的实例:
#!/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)
以上实例运行后输出结果为:
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
-
扫码下载安卓APP
-
微信扫一扫关注我们
微信扫一扫打开小程序
手Q扫一扫打开小程序
-
返回顶部
友情链接:
6547题库网 |
Scratch从入门到精通|
Copyright © 小码农 |
2020-2022
发表评论