In this post, we will see how to find square root of a number in python.
There are many ways to do it but I will discuss below two
- Using ** operator
- Using math library
Using ** operator
As you might know, you can use ** to find power of number in python. If you want square root, you can simply use 0.5 with number.
num=25 sqrtRoot=num**0.5 print(sqrtRoot)
But above approach will work only for positive numbers, you need to use other ways for negative numbers.
Using math library
you can import math package and use math.sqrt to find square root of a number.
import math num=25 sqrtRoot=math.sqrt(num) print(sqrtRoot)
That’s all about finding square root of a number in pyhton.