为什么 0 ** 0
在 Python 中等于 1
?它不应该像 0/0
那样抛出异常吗?
最佳答案
维基百科对 history and the differing points of view on 有有趣的报道。 0 ** 0
的值:
The debate has been going on at least since the early 19th century. At that time, most mathematicians agreed that
0 ** 0 = 1
, until in 1821 Cauchy listed0 ** 0
along with expressions like0⁄0
in a table of undefined forms. In the 1830s Libri published an unconvincing argument for0 ** 0 = 1
, and Möbius sided with him...
应用于计算机时,IEEE 754推荐了几个计算幂的函数。它将 pow(0, 0)
和 pown(0, 0)
定义为返回 1
和 powr(0, 0)
作为返回 NaN
。
大多数编程语言都遵循 0 ** 0 == 1
的约定。对于整数和浮点参数,Python 也不异常(exception)。
关于python - 为什么 0 ** 0 在 python 中等于 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14414430/