Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why 0 ** 0 equals 1 in python

Tags:

python

math

Why does 0 ** 0 equal 1 in Python? Shouldn't it throw an exception, like 0 / 0 does?

like image 749
kaspersky Avatar asked Jan 19 '13 12:01

kaspersky


People also ask

What does == 0 mean in Python?

Answer 557d6f2fe0a3006892000915 number % 2 == 0 is a valid boolean expression that checks whether number % 2 is equivalent to 0 . For even number s, the result is the value, True . But, number 2% == 0 is not a valid expression, because % == is not a valid operator. Submitted by Glenn Richard.

Is 0 the same as 0 in Python?

Python returns the first character of a string when either of these are used as index values. 0 and -0 are the same.

What does 0 ]* n mean in Python?

X =[0] * N , produces a list of size N, with all N elements being the value zero. for example, X = [0] * 8 , produces a list of size 8.

What is the meaning of 0 and 1 in Python?

It is a mathematical notation for an "open range" or "half closed interval". The notation has no use in common programming languages, including Python. In this case, it means "all the representable numbers between 0 and 1, excluding 1".


1 Answers

Wikipedia has interesting coverage of the history and the differing points of view on the value of 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 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...

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.

Most programming languages follow the convention that 0 ** 0 == 1. Python is no exception, both for integer and floating-point arguments.

like image 96
NPE Avatar answered Sep 22 '22 23:09

NPE