Python Math sqrt() Method
The Python Math sqrt() method returns the square root of the number x.
Python Math sqrt() Syntax
Here is the syntax of the sqrt() method:
import math
math.sqrt( x )
Note: sqrt() is not directly accessible, you need to import the math module and call the method through a static object.
Python Math sqrt() Parameters
- x – The numeric expression.
Python Math sqrt() Return Value
Returns the square root of the number x.
Python Math sqrt() Example#1
The following shows an example of using the sqrt() method.
#!/usr/bin/python3
import math
print(math.sqrt(0))
print(math.sqrt(4))
print(math.sqrt(3.5))
Output:
Python Math sqrt() Example#2
#!/usr/bin/python3
import math
# print the error when x<0
print(math.sqrt(-1))
Output: