Python3 sqrt()函数

 sqrt()方法返回 x (x>0) 的平方根。

语法

以下是 sqrt() 方法的语法:
import math

math.sqrt( x )

注:此函数无法直接访问,所以我们需要导入 math 模块,然后用数学静态对象调用这个函数。

参数

  • x -- 这是一个数字表达式

返回值

这个方法返回 x (x>0) 的平方根。

示例

下面的例子显示 sqrt()方法的使用。
#!/usr/bin/python3
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))
当我们运行上面的程序,它会产生以下结果:
math.sqrt(100) :  10.0
math.sqrt(7) :  2.6457513110645907
math.sqrt(math.pi) :  1.7724538509055159

上一篇: Python3循环 下一篇: Python3数字