How to use the sqrt function in Python? The following is an introduction to the sqrt function:
The Python number sqrt() function returns the square root of x (x > 0).
Syntax
The following is the syntax of the sqrt() method-
import math
math.sqrt( x )
Note - This function is not directly accessible, you need to import the math module, and then you need to use the math static object to call this function.
Parameters
x - This is a numeric expression.
Return value
This method returns the square root of x (x > 0).
sqrt() method returns the square root of the number x.
Related recommendations: "Python Video Tutorial"
Example
import math # 导入 math 模块 print ("math.sqrt(100) : ", math.sqrt(100)) print ("math.sqrt(7) : ", math.sqrt(7)) print ("math.sqrt(math.pi) : ", math.sqrt(math.pi))
The output result after running the above example is :
math.sqrt(100) : 10.0 math.sqrt(7) : 2.6457513110645907 math.sqrt(math.pi) : 1.7724538509055159
The above is the detailed content of How to use the sqrt function in Python. For more information, please follow other related articles on the PHP Chinese website!