Skip to content

Python math sqrt() function

  • by

The math.sqrt() function in Python is a part of the math module and is used to calculate the square root of a given number. The sqrt() function takes a single argument, x, which represents the number for which you want to calculate the square root.

Here’s the syntax of the math.sqrt() function:

import math

math.sqrt(x)

The math module provides various mathematical functions and constants and sqrt() is one of them. It returns the square root of the argument x as a floating-point number.

Python math sqrt() function example

Simple example code.

import math

number = 16
result = math.sqrt(number)
print("The square root of", number, "is:", result)

Output:

Python math sqrt() function

In this example, we import the math module. We then define the variable number and assign it the value 16. The sqrt() function is called with number as the argument, and the result is stored in the variable result. Finally, we print the result along with a descriptive message.

Comment if you have any doubts or suggestions on this Python math module.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading