Python provides different mathematical functions and calculations via the math
module. The sqrt()
is one of the most used functions to calculate the square root of the provided number.
sqrt() Method Syntax
The sqrt() function has very simple syntax where the number we want to calculate its square root is provided as a parameter. But in order to use the sqrt() method, the “math” module should be imported. The calculated square root is returned as a floating-point number.
sqtr(NUMBER)
- NUMBER is the number which square root will be calculated.
The math module can be imported like below.
import math
Square Root of Integer
One of the most popular use cases for the sqtr() method is calculating the square root of an integer. In the following example, we calculate square roots of different integer values, numbers, and variables.
import math
a = 9
print(math.sqrt(a))
print(math.sqrt(25))
Square Root of Floating Point
The sqrt() method can be also used to calculate the square root of a floating-point number.
import math
a = 9
print(math.sqrt(a))
print(math.sqrt(25))