數學常量



e

數學常數 e 被稱為**尤拉數**。

語法

math.e

返回值

math.e 常量等於尤拉數。

示例

from math import e

print ("Euler's Number: ",e)

它將產生以下**輸出** -

Euler's Number: 2.718281828459045

pi

在數學中,pi(表示為 Π)是一個數學常數,等於圓的周長與其直徑之比。

語法

math.pi

返回值

math.pi 常量返回周長/直徑。

示例

from math import pi

print ("Mathematical constant Π: ",pi)

它將產生以下**輸出** -

Mathematical constant Π: 3.141592653589793

tau

在數學中,Tau(表示為 τ)定義為一個數學常數,等於圓的周長與其半徑之比,等於 2Π。

語法

math.tau

返回值

math.tau 返回周長/半徑。

示例

from math import tau

print ("Mathematical constant τ : ",tau)

它將產生以下**輸出** -

Mathematical constant τ : 6.283185307179586

inf

此數學常數等價於正無窮大。對於負無窮大,請使用 - math.inf。這等價於 float("Inf")。

語法

math.inf

返回值

該常量返回正無窮大。

示例

from math import inf

print ("Positive infinity: ",inf, "is equal to", float("Inf"))
print ("Negative infinity: ",-inf, "is equal to", float("-Inf"))

它將產生以下**輸出** -

Positive infinity: inf is equal to inf
Negative infinity: -inf is equal to -inf

nan

此常量是一個浮點“非數字”(NaN)值。等價於 float('nan') 的輸出。

語法

math.nan

返回值

此常量返回 NaN,代表非數字。

示例

from math import nan

print ("Not a number:", nan, "is equal to", float("nan"))

它將產生以下**輸出** -

Not a number: nan is equal to nan
python_maths.htm
廣告