The Easiest Way to Use the Python Square Root Function



This tutorial shows two different ways to find the square root of a number in Python. One of the methods uses the exponent operator and the other uses a python’s native module.

1. Background of Square Root

Squaring the length of the sides gives the area of a square. So, if a refers to the area of the square and x refers to the length of the side of the square, then the area of the square is given by the formula: a = x 2

This formula is easy to calculate area when we know the length z. But in case we know the area and we need to calculate the length x of the square, then we first refer the unknown length by some name called square root. Of course, this is actually the answer to the discussed square problem. So, we use a square root function to calculate its value. Here we are passing the area as the input to the square root function to get the output of the length of the square side.

2. Definition of the Square Root Function

The definition of the square root function in a formal way is as below:

The square root function is defined as a function that takes any positive number as its input and returns the positive number that might need to be squared i.e., in other words, the output of square root function, when multiplied by itself will be equal to the input passed.

3. Square Root Symbol

The symbol is known as the radical symbol. The quantity or value ‘y’ that is inside the radical symbol is known as the argument of the square root function. in the Algebra Coach, in general, it is important to remember that, the square root of y should be written or typed as: sqrt (y).

4. Easiest Way to Use the Python Square Root Function

The easiest way to find the square root of a number if to use the exponent operator and raise a number to the power of “1/2”

Please see code below:

$ x = 9 ** (1/2)
$ x
$ 3


$ x = 9 ** 0.5
$ x
$ 3

Easy, isn’t it?

5. Square Root Function Using the Math module

Moreover, another way is to simply use the math module which has a method to find the square root of a given number. See below:

$ import math

$ x = math.sqrt(9)
$ x
$ 3

$ x = math.sqrt(16)
$ x
$ 4

Related Posts