How to Calculate Square Root in Python using sqrt() Function

To find out the square root in Python Programming Language you can use math.sqrt() function of Standard Library.

Python sqrt() Function

math.sqrt() function exists in Standard math Library of Python Programming Language. The purpose of this function is to calculate squar root of a given value x. x must be greater than zero (x>0).


Python sqrt() Function Syntax

The syntax of sqrt function in python is:
math.sqrt( x )


Python sqrt() Function Parameters

x – Any valid Python positive number. This parameter is required.
Note: if the x parameter is not a number returns an error.


Python sqrt() Function Compatibility

Python 2.x – Yes
Python 3.x – Yes


Python sqrt() Return Value

sqrt() function will return an integer or a floating point number after calculating squar root. The return value will always be greater than zero.


Python sqrt() Function Examples

# import math library
import math
print (math.sqrt(0))
print (math.sqrt(4))
print (math.sqrt(5.5))
print (math.sqrt(-2.9))

Output of Python sqrt() function:

ValueError: math domain error