Python/ref math perm
来自菜鸟教程
<languages />
Python math.perm()方法
例
查找选择方式的数量 k 来自的东西 n 项目:
# Import math Library
import math
# Initialize the number of
items to choose from
n = 7
# Initialize the number of items
to choose
k = 5
# Print the number of ways to choose k items from
n items
print
(math.perm(n, k))
结果将是:
2520
定义和用法
The
math.perm()
方法返回有序,无重复地从n个项中选择k个项的方式数。
注意: The k 参数是可选的。如果我们不提供,则此方法将返回 n ! (例如,math.perm(7)将返回5040)。
句法
math.perm(n, k)
参数值
| 参数 | 描述 |
|---|---|
| n | 需要。正整数项目可供选择 |
| k | 可选的。正整数项目可供选择 |
注意: If k 大于 n ,则返回0。
注意: If n or k 如果为负,则发生ValueError。If n or k 不是整数,则发生TypeError。
技术细节
| 返回值: | An
|
| Python版本: | 3.8 |