# How to Find Square Root in Python

Hello everyone, in this tutorial, I’ll show 3 ways to find square root in Python.

Let’s see how to do it.

1. Using Exponent

Output:

enter a number: 64
square root: 8.0

In above program, first we’re taking a number from user as input and the entered value will be converted to int from string and will store into variable called number. Then we are using  exponent (**) sign, which is used to find out the power of a number. But we know that if a number have power ½ or 0.5 then it will represent to the square root of that number. That’s why we are using 0.5 as power here. So the number**0.5 will give us square root of that number and will be stored in variable named as sqrt. In last line we’re just printing the square root of the number.

2. Using math.sqrt() Method

sqrt() is the predefined method used to find square root in python. But we have to import math module to use the sqrt() method. In first line, we’re importing math module, then in next line, taking input from user. After that we’re finding the square root of the number using sqrt() method and result will be stored into sqrt variable. In last line, just printing the square root as in first program.

3. Using math.pow() Method

pow() is also a predefined method to find out power of a number, it takes two arguments as input, first is the number itself and second one is power of that number. The program is same as first program where we’re using (**) sign to find out the square root but only different is this that here we’re using a predefined method pow() instead of  (**) sign to get the power of that number.

If you’ve any problem related with article or have any other possible way to find square root in python then please let us know in comments.

### 7 thoughts on “How to Find Square Root in Python”

1. Yakub shakirudeen olaide

Another way

Example to find square root of 4
Solution
S=4
Sqrt=//4
Print (sqrt)

1. It’s an error here.
Invalid syntax:

2. Every time I attempt to use sqrt in python, an invalid syntax error is thrown at the first parentheses. Any advice would be greatly appreciated.

3. Awharitoma kenneth

import math
number = int(input(“entre a value please? “)
sqrt = math.sqrt(number))
print(sqr)

by Awharitoma Kenneth

4. Write import math first

5. def is_prime(n):
if n < 2:
return False
import math
for i in range(2,int(math.sqrt(n))+1):
if n % i == 0:
return False
return True

6. import math

number = float(input(“Enter a number: “))
sqrt = math.sqrt(number)
print(“The square root of”,number,”is”,sqrt)