为什么0 ** 0在python中等于1 [英] Why 0 ** 0 equals 1 in python
问题描述
为什么在Python中0 ** 0
等于1
?它不应该像0 / 0
一样引发异常吗?
Why does 0 ** 0
equal 1
in Python? Shouldn't it throw an exception, like 0 / 0
does?
推荐答案
Wikipedia对历史记录进行了有趣的报道.以及关于0 ** 0
值的的不同观点:
Wikipedia has interesting coverage of the history and the differing points of view on the value of 0 ** 0
:
至少从19世纪初期开始,辩论就一直在进行.当时,大多数数学家都同意
0 ** 0 = 1
,直到1821年,柯西在未定义形式的表格中列出了0 ** 0
以及类似0⁄0
的表达式.在1830年代,里布里(Libri)对0 ** 0 = 1
发表了令人信服的论点,莫比乌斯(Möbius)站在他旁边...
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
.
As applied to computers, IEEE 754 recommends several functions for computing a power. It defines pow(0, 0)
and pown(0, 0)
as returning 1
, and powr(0, 0)
as returning NaN
.
大多数编程语言都遵循0 ** 0 == 1
的约定.对于整数和浮点参数,Python也不例外.
Most programming languages follow the convention that 0 ** 0 == 1
. Python is no exception, both for integer and floating-point arguments.
这篇关于为什么0 ** 0在python中等于1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!