Python3 log()函數

該log()方法返回x的自然對數(x>0)。

語法

以下是 log()方法的語法:
import math

math.log( x )

注:此函數無法直接訪問,所以我們需要導入 math 模組,然後用數學靜態對象調用這個函數。

參數

  • x -- 這是一個數字運算式。

返回值

這個方法返回x的自然對數(x>0)

實例

下麵的示例說明 log() 方法的使用。
#!/usr/bin/python3
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(math.pi) : ", math.log(math.pi))

當我們運行上面的程式,它會產生以下結果:
math.log(100.12) :  4.6063694665635735
math.log(100.72) :  4.612344389736092
math.log(math.pi) :  1.1447298858494002

上一篇: Python3迴圈 下一篇: Python3數字