⊕
⊖
Contents
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.
Python Program
import math
x = math.inf
result = math.sqrt(x)
print('sqrt(x) :', result)
Run Code CopyOutput
sqrt(x) : inf
Square root of decimal value.
Output
sqrt(x) : 0.03162277660168379
Square root of nan.
Python Program
import math
x = math.nan
result = math.sqrt(x)
print('sqrt(x) :', result)
Run Code CopyOutput
sqrt(x) : nan
Summary
In this Python Examples tutorial, we learned the syntax of, and examples for math.sqrt() function.