天天看點

Python math.log1p() 方法

Python math 子產品

Python math.log1p(x) 方法傳回 1+x 的自然對數(以 e 為底)。

文法

math.log1p() 方法文法如下:

math.log1p(x)      

參數說明:

  • x -- 必需,數字。如果 x 不是一個數字,傳回 TypeError。如果值為 0 或負數,則傳回 ValueError。

傳回值

傳回一個整數浮點數 float,表示 1+x 以 e 為底的自然對數。

執行個體

以下執行個體傳回一個 1+x 以 e 為底的自然對數:

執行個體

# 導入 math 包

import math

# 輸出 1+x 以 e 為底的自然對數

print(math.log1p(2.7183))

print(math.log1p(2))

print(math.log1p(1))

輸出結果:

1.313266574586334
1.0986122886681098
0.6931471805599453
      

Python math 子產品