Exponentiation using the math module math.pow

suggest change

The math-module contains another math.pow() function. The difference to the builtin pow()-function or ** operator is that the result is always a float:

import math
math.pow(2, 2)    # 4.0
math.pow(-2., 2)  # 4.0

Which excludes computations with complex inputs:

math.pow(2, 2+0j)
TypeError: can’t convert complex to float

and computations that would lead to complex results:

math.pow(-2, 0.5)
ValueError: math domain error

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents