Python Language Exponentiation Exponentiation using the math module: math.pow()

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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



Got any Python Language Question?