In mathematics, the square root of a number is a value that, when multiplied by itself, gives the original number. It is denoted by the radical symbol (√) or by using the exponent 0.5. For example, the square root of 9 is 3 because 3 * 3 = 9. In Python, you can calculate square roots of a positive number using the `sqrt`

function from the `math`

module or by using the exponent operator (`**`

). If you want to calculate the square root for complex numbers you can use the `cmath.sqrt()`

fucntion from the `cmath`

module.

```
import math
# Using math.sqrt
positive_number = 9
result = math.sqrt(positive_number)
print(f"Square root of {positive_number} is {result}")
# Using exponent operator
result_exponent = positive_number ** 0.5
print(f"Square root of {positive_number} using exponent is {result_exponent}")
```

Output:

```
Square root of 9 is 3.0
Square root of 9 using exponent is 3.0
```

Note: the result of the operation is always

`float`

even if you start with integers and the result could be integer.

For the square root of a negative number, Python’s `math.sqrt`

function will raise a `ValueError`

because square roots of negative numbers are not defined in the real number system.

Example

```
import math
# Using math.sqrt
negative_number = -9
result = math.sqrt(negative_number)
print(f"Square root of {negative_number} is {result}")
```

This will raise `ValueError: math domain error`

However, you can work with complex numbers using the `cmath`

module:

```
import cmath
negative_number = -9
result_complex = cmath.sqrt(negative_number)
print(f"Square root of {negative_number} (as a complex number) is {result_complex}")
```

Output:

```
Square root of -9 (as a complex number) is 3j
```

The type of result_complex is `complex`

.

- How to copy files in Python
- Python Read JSON file
- How to Subtract in Python
- Python max() function explained
- Python Bytes to String Conversion
- Python ModuleNotFoundError: No module named 'pandas' - how to fix it
- Python: get current directory
- Python ModuleNotFoundError: No module named 'bs4' - how to fix it
- Python ModuleNotFoundError: No module named 'httlib2' - how to fix it
- 'No module named' error in Python: how to fix it