Python math.sqrt()
math.sqrt(x) function returns the square root of x.
Syntax
The syntax to call sqrt() function is
math.sqrt(x)
where
Parameter | Required | Description |
---|---|---|
x | Yes | A numeric value. |
If x < 0, then sqrt() raises ValueError.
Examples
Square root of 3.
Output
sqrt(x) : 1.7320508075688772
Square root of a negative number. sqrt() raises ValueError.
Output
ValueError: math domain error
Square root of infinity.
Output
sqrt(x) : inf
Square root of decimal value.
Output
sqrt(x) : 0.03162277660168379
Square root of nan.
Output
sqrt(x) : nan
Summary
In this Python Examples tutorial, we learned the syntax of, and examples for math.sqrt() function.
Next Topic ⫸
Python Math log()
⫷ Previous Topic
Python Math pow()