Python math.sqrt() Method

Python math.sqrt() method “returns the square root of any number.”




x: It is any number such that x>=0. The sqrt() function takes a number as an argument.

Return Value

It returns the square root of a number argument.

Example 1: How to Use math.sqrt() Method

Import math module to work with mathematical operations in Python.

import math


Python Math Square Root Tutorial

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

Example 2: Passing positive argument

Another way will give us the same output, but the number must be positive, not negative, and not complex.

num = 49

sq_root = num ** 0.5


Python Sqrt Example

Example 3: Passing a complex number

To calculate a square root of a complex number in Python, use the cmath module. To use the cmath module, you must import it and then use its sqrt() function.

import cmath

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


Python Sqrt Example | Python Math Square Root Tutorial

That’s it.

Leave a Comment

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