In this Python example series we will study about how to find Square root of a number.
Square root is Math function of Python. To get the Square root in Python we use sqrt(x) function of math module.
Syntax of Square root in Python
Math. sqrt(x)
- Math is module, and it has sqrt() as a function to calculate square root of variable x.
- sqrt(x) return the output in decimal format.
Example of Square root in Python
Let’s understand Square root by taking simple examples.
import math tup1=(4,9,16,25,36,49) for x in tup1 : print("Square root of",x,"is :",math.sqrt(x))
Output
Square root of 4 is : 2.0 Square root of 9 is : 3.0 Square root of 16 is : 4.0 Square root of 25 is : 5.0 Square root of 36 is : 6.0 Square root of 49 is : 7.0
Explanation:
- To use the sqrt() function in Python, we have to import math module.
- In above example, we have taken Python tuple and add some elements into it.
- Inside loop, we are iterating each element of tuple and applying sqrt(x) function to get square root of element.