How to Use the sqrt () method to calculate the square root in Python
This article describes how to use the sqrt () method to calculate the square root in Python. It is a basic knowledge of Python learning. For more information, see
The sqrt () method returns the square root of x (x> 0 ).
Syntax
The syntax of the sqrt () method is as follows:
?
1 2 3 |
Import math Math. sqrt (x) |
Note: This function cannot be directly accessed. Therefore, we need to import the math module and then use the static object of math to call this function.
Parameters
- X -- this is a numeric expression.
Return Value
This method returns the square root of x, for x> 0.
Example
The following example shows how to use the sqrt () method.
?
1 2 3 4 5 6 |
#! /Usr/bin/python Import math # This will import math module Print "math. sqrt (100):", math. sqrt (100) Print "math. sqrt (7):", math. sqrt (7) Print "math. sqrt (math. pi):", math. sqrt (math. pi) |
When we run the above program, it will produce the following results:
?
1 2 3 |
Math. sqrt (100): 10.0 Math. sqrt (7): 2.64575131106 Math. sqrt (math. pi): 1.77245385091 |