Back to Blog Home

How to Calculate Square Root in Python

Jay Mishra| Python | 6 months, 2 weeks



 

To calculate the square root of a number in python , we can use sqrt() method which returns the square root of number ( given that the number is > 0 )

 

To use the sqrt() function in python, we need to import the math module which provides access to the mathematical functions defined by the C standard.

 

So syntax to calculate python square root looks simply like this :

 

import math

math.sqrt( x )

 

where x is > 0

 

So for example :

 

import math   # This will import math module

print “Square Root of 49 is ", math.sqrt(49)

 

Output :

 

Square Root of 49 is 7.0

 

method sqrt() returns a float value. 

 



Join 1000+ People Who Subscribe to Weekly Blog Updates

Back to Blog Home