Why does 0**0 equal 1 and 0/0 raise a zero division error in Python?

Asked by Alexandros

If you type 0**0<Enter> in the Python interpreter, the number 1 will be printed.
If you type 0/0<Enter>, however, a zero division error is raised.
Why does this happen?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu python-defaults Edit question
Assignee:
No assignee Edit question
Solved by:
Ilya Barygin
Solved:
Last query:
Last reply:
Revision history for this message
Best Ilya Barygin (randomaction) said :
#1

From http://docs.python.org/library/exceptions.html#bltin-exceptions:

exception ZeroDivisionError
    Raised when the second argument of a division or modulo operation is zero. The associated value is a string indicating the type of the operands and the operation.

From http://docs.python.org/library/math.html:

Return x raised to the power y. Exceptional cases follow Annex ‘F’ of the C99 standard as far as possible. In particular, pow(1.0, x) and pow(x, 0.0) always return 1.0, even when x is a zero or a NaN.

Revision history for this message
Alexandros (alexandros-t) said :
#2

Thanks Ilya Barygin, that solved my question.