Python math.factorial()メソッド
例
数の階乗を見つけます:
#Import math Library
import math
#Return factorial of a number
print(math.factorial(9))
print(math.factorial(6))
print(math.factorial(12))
定義と使用法
このmath.factorial()
メソッドは、数値の階乗を返します。
注:このメソッドは正の整数のみを受け入れます。
数値の階乗は、指定された数値から1までのすべての整数の乗算の合計です。たとえば、6の階乗は6 x 5 x 4 x 3 x 2 x 1 = 720になります。
構文
math.factorial(x)
パラメータ値
Parameter | Description |
---|---|
x | Required. A positive integer. If the number is negative, or not an integer, it returns a ValueError. If the value is not a number, it returns a TypeError |
技術的な詳細
戻り値: | 正のint 値 |
---|---|
Pythonバージョン: | 2.62.6 |