python中对数函数怎么表示


本文摘自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 中的int()函数怎么用

编程Python是什么

Python编程时如何添加中文注释

Python之读取txt文件的方法

Python该怎么学才快

Python中demo是什么

Python画星空源代码是什么?

最有用的Python经典书籍推荐

Python中命名空间的三种方式介绍(附示例)

Python中字符串和数组相互转换功能的实现示例

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...