python中如何写入log函数

655Z技术栈 Python编程 2025年08月16日 21

在python中使用log函数的方法

在python中使用log函数时,log()函数无法直接访问,需要先导入math模块,在通过静态对象调用;

log():log函数的作用是返回一个数的自然对数。

log()函数语法:

import math

math.log(x[, base])

使用方法:

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

提供PHP及ThinkPHP框架的定制开发、代码优化,PHP修改、ThinkPHP修改。

邮箱:yvsm@163.com 微信:yvsm316 QQ:316430983
关闭

用微信“扫一扫”