Find Square root of a number in Python

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.

 

 

 

 

Please follow and like us:
READ  Write a program to check Prime number in Python

One Comment to “Find Square root of a number in Python”

  1. […] one of our previous post of find Square root of a number in Python. we have used statement […]

Comments are closed.