为什么0 ** 0在python中等于1 [英] Why 0 ** 0 equals 1 in python

查看:401
本文介绍了为什么0 ** 0在python中等于1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在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 listed 0 ** 0 along with expressions like 0⁄0 in a table of undefined forms. In the 1830s Libri published an unconvincing argument for 0 ** 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆