python - 为什么 python math.factorial(x) 非常快?

标签 python

<分区>

我有一个疑问,为什么python的数值计算非常快? 例如下面的代码运行不到一秒

import  math
print math.factorial(10000)

为什么???

最佳答案

math module's functions在 C 中实现:

It provides access to the mathematical functions defined by the C standard.

通过使用 C 语言中的高效算法,您可以快速获得结果。

如果您要问为什么这个特定操作如此之快,请参阅 Why is math.factorial much slower in Python 2.x than 3.x?C code itself .

关于python - 为什么 python math.factorial(x) 非常快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11313998/

相关文章:

Python将数组中的unicode字符串打印为字符,而不是代码点

python - 导入 glob,语法无效 python

python - 所得税计算python

python - Pytest 断言在 AssertionError 上没有显示差异

python - Pandas 数据框分配不更新数据框

python - 动画不适用于日期时间 X 值,但适用于整数

python - 如何使用 PyGObject 使窗口居中

python - 如何将utf-8输出重定向到txt文件

python - 通过 Pexpect 减少戒烟

python - 有一个 numpy.dot 文档示例不清楚,具有高维点积