新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:python中的對(duì)數(shù)怎么寫
這篇文章主要介紹了Python中用于計(jì)算對(duì)數(shù)的log()方法,是Python入門基礎(chǔ)中的必會(huì)的方法,需要的朋友可以參考下

log()方法返回x的自然對(duì)數(shù),對(duì)于x>0。
語(yǔ)法
以下是log()方法的語(yǔ)法:
import math math.log( x )
注意:此函數(shù)是無(wú)法直接訪問(wèn)的,所以我們需要導(dǎo)入math模塊,然后需要用math的靜態(tài)對(duì)象來(lái)調(diào)用這個(gè)函數(shù)。
參數(shù)
x -- 這是一個(gè)數(shù)值表達(dá)式。
返回值
此方法返回x的自然對(duì)數(shù),對(duì)于x>0。
例子
下面的例子顯示了log()方法的用法。
#!/usr/bin/python import math # This will import math module 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)
當(dāng)我們運(yùn)行上面的程序,它會(huì)產(chǎn)生以下結(jié)果:
math.log(100.12) : 4.60636946656 math.log(100.72) : 4.61234438974 math.log(119L) : 4.77912349311 math.log(math.pi) : 1.14472988585
更多學(xué)習(xí)內(nèi)容,請(qǐng)點(diǎn)擊Python學(xué)習(xí)網(wǎng)!
本文標(biāo)題:創(chuàng)新互聯(lián)Python教程:python中的對(duì)數(shù)怎么寫
轉(zhuǎn)載來(lái)源:http://www.dlmjj.cn/article/ccedsco.html


咨詢
建站咨詢
