Python cmath.sqrt() 方法
实例
求复数的平方根:
# 导入 cmath 库import cmath#Return the square root of a complex numberprint (cmath.sqrt(2 + 3j))print (cmath.sqrt(15))
定义与用法
cmath.sqrt() 方法返回复数的平方根。
注意:数字必须大于或等于 0。
语法
cmath.sqrt(x)
参数值
| 参数 | 描述 |
|---|---|
| x | 必填。求其平方根的数字。如果数字小于 0,则返回 ValueError。如果该值不是数字,则返回 TypeError |
技术细节
| 返回值: | 一个 complex 值,表示复数的平方根 |
|---|---|
| Python 版本: | 1.5 |