教程集 www.jiaochengji.com
教程集 >  Python编程  >  Python入门  >  正文 python log函数怎么用

python log函数怎么用

发布时间:2021-04-10   编辑:jiaochengji.com
教程集为您提供python log函数怎么用等资源,欢迎您收藏本站,我们将为您提供最新的python log函数怎么用资源

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

语法

以下是 log() 方法的语法:

import math
math.log(x[, base])

相关推荐:《Python视频教程》

注意: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

您可能感兴趣的文章:
python中怎么计算log对数
python log函数怎么用
python log运算如何写
python装饰器以什么开头
python中怎么保留小数
python里怎么调用函数
python lambda怎么用
python定义的类怎么用
python 重载内置函数吗
python怎么生成随机不重复数组

[关闭]
~ ~