Linux 拨号vps windows公众号手机端

python中如何写入log函数

lewis 6年前 (2019-04-08) 阅读数 12 #程序编程
文章标签 python

在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

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门