AppDividend
Latest Code Tutorials

# Python Sqrt Example | How To Calculate Square Root In Python

Python sqrt() is an inbuilt math library function that returns square root of x for x > 0. We can import the math module and then call the sqrt() function to get the square root of any given value.

## Python Sqrt Example

If you are looking to find a solution regarding calculate square root in Python then use the sqrt() function.

The syntax for Python sqrt() function is the following.

`math.sqrt(number)`

See the following example.

```# app.py

import math

print(math.sqrt(81))
```

See the output.

It is the best way to find the square root of any number.

Now, there is one another way that will give us the same output, but the number must have positive, not negative and not complex. See the below example.

```// app.py

num = 49

sq_root = num ** 0.5
print(sq_root)```

See the output.

Now, if we want to get the square root of a complex number, then we can use the cmath module.

See the following example.

```// app.py

import cmath

print(cmath.sqrt(1 + 2j))
```

See the output.

Let’s find the square root of the float value. See the following example.

```// app.py

import math

print(math.sqrt(math.pi))
```

See the output.

Finally, Python Sqrt Example | Python Math Square Root Tutorial is over.

This site uses Akismet to reduce spam. Learn how your comment data is processed.