math.comb(n, k)n 個項目中選擇 k 個項目的組合數,不重複且無順序。math.comb(n, k)
n (int): 項目總數。k (int): 選擇的項目數。import math
print(math.comb(5, 2)) # 輸出: 10
math.copysign(x, y)x 的大小(絕對值)但具有 y 符號的浮點數。math.copysign(x, y)
x (float): 要複製絕對值的數值。y (float): 提供符號的數值。x 的絕對值但帶有 y 的符號。import math
print(math.copysign(3, -2)) # 輸出: -3.0
math.fabs(x)x 的絕對值,作為浮點數。math.fabs(x)
x (float): 要計算絕對值的數值。x 的絕對值,作為浮點數。import math
print(math.fabs(-3.14)) # 輸出: 3.14
math.factorial(n)n 的階乘。math.factorial(n)
n (int): 要計算階乘的整數。n 的階乘。import math
print(math.factorial(5)) # 輸出: 120
math.floor(x)x 的最大整數。math.floor(x)
x (float): 要取整的數值。x 向下取整後的整數。import math
print(math.floor(3.9)) # 輸出: 3