本文介绍了为什么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:

应用于计算机的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 12:35