Why does 0 ** 0
equal 1
in Python? Shouldn't it throw an exception, like 0 / 0
does?
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.
Python returns the first character of a string when either of these are used as index values. 0 and -0 are the same.
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.
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".
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 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...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With