Python math Module
Python math 模組
Python 有一個內建模組可用於數學任務。
math
模組包含一組方法和常量。
Math 方法
方法 | 描述 |
---|---|
math.acos() | 返回數字的反正餘弦值 |
math.acosh() | 返回數字的逆雙曲餘弦值 |
math.asin() | 返回數字的反正弦值 |
math.asinh() | 返回數字的逆雙曲正弦值 |
math.atan() | 以弧度為單位返回數字的反正切值 |
math.atan2() | 以弧度為單位返回 y/x 的反正切值 |
math.atanh() | 返回數字的逆雙曲正切值 |
math.ceil() | 將數字向上舍入到最接近的整數 |
math.comb() | 返回從 n 個專案中選擇 k 個專案而不重複和不考慮順序的組合數 |
math.copysign() | 返回一個浮點數,其值為第一個引數,符號為第二個引數 |
math.cos() | 返回數字的餘弦值 |
math.cosh() | 返回數字的雙曲餘弦值 |
math.degrees() | 將角度從弧度轉換為度 |
math.dist() | 返回兩個點(p 和 q)之間的歐幾里得距離,其中 p 和 q 是該點的座標 |
math.erf() | 返回數字的誤差函式 |
math.erfc() | 返回數字的互補誤差函式 |
math.exp() | 返回 E 的 x 次冪 |
math.expm1() | 返回 Ex - 1 |
math.fabs() | 返回數字的絕對值 |
math.factorial() | 返回數字的階乘 |
math.floor() | 將數字向下舍入到最接近的整數 |
math.fmod() | 返回 x/y 的餘數 |
math.frexp() | 返回指定數字的尾數和指數 |
math.fsum() | 返回任何可迭代物件(元組、陣列、列表等)中所有元素的總和 |
math.gamma() | 返回 x 的伽馬函式 |
math.gcd() | 返回兩個整數的最大公約數 |
math.hypot() | 返回歐幾里得範數 |
math.isclose() | 檢查兩個值是否接近 |
math.isfinite() | 檢查數字是否是有限的 |
math.isinf() | 檢查數字是否是無窮大的 |
math.isnan() | 檢查值是否為 NaN(非數字) |
math.isqrt() | 將平方根數向下舍入到最接近的整數 |
math.ldexp() | 返回 math.frexp() 的逆運算,即給定數字 x 和 i 的 x * (2**i) |
math.lgamma() | 返回 x 的對數伽馬值 |
math.log() | 返回數字的自然對數,或以某數為底的對數 |
math.log10() | 返回 x 的以 10 為底的對數 |
math.log1p() | 返回 1+x 的自然對數 |
math.log2() | 返回 x 的以 2 為底的對數 |
math.perm() | 返回從 n 個專案中選擇 k 個專案(考慮順序且不重複)的排列數 |
math.pow() | 返回 x 的 y 次冪的值 |
math.prod() | 返回可迭代物件中所有元素的乘積 |
math.radians() | 將度數轉換為弧度 |
math.remainder() | 返回能使分子完全被分母整除的最接近的值 |
math.sin() | 返回數字的正弦值 |
math.sinh() | 返回數字的雙曲正弦值 |
math.sqrt() | 返回數字的平方根 |
math.tan() | 返回數字的正切值 |
math.tanh() | 返回數字的雙曲正切值 |
math.trunc() | 返回數字的截斷整數部分 |
Math 常量
常量 | 描述 |
---|---|
math.e | 返回尤拉數(2.7182...) |
math.inf | 返回浮點正無窮大 |
math.nan | 返回浮點 NaN(非數字)值 |
math.pi | 返回 PI(3.1415...) |
math.tau | 返回 tau(6.2831...) |