Python math.sqrt() 方法
实例
求不同数字的平方根:
# 导入 math 库import math# 返回不同数字的平方根print (math.sqrt(9))print (math.sqrt(25))print (math.sqrt(16))
定义与用法
math.sqrt() 方法返回数字的平方根。
注意:数字必须大于或等于0。
语法
math.sqrt(x)
参数值
| 参数 | 描述 |
|---|---|
| x | 必填。求其平方根的数字。如果数字小于0,则返回 ValueError。如果该值不是数字,则返回 TypeError |
技术细节
| 返回值: | 一个 float 值,表示数字的平方根 |
|---|---|
| Python 版本: | 1.4 |