Python cmath.sqrt() 方法
定义和用法
cmath.sqrt()
方法返回复数的平方根。
注意:数字必须大于或等于 0。
实例
计算复数的平方根:
# 导入 cmath 库 import cmath # 返回复数的平方根 print (cmath.sqrt(2 + 3j)) print (cmath.sqrt(15))
语法
cmath.sqrt(x)
参数
参数 | 描述 |
---|---|
x |
必需。要计算其平方根的数字。 如果数字小于 0,则返回 ValueError。 如果值不是数,则返回 TypeError。 |
技术细节
返回值: | 复数值,表示复数的平方根。 |
---|---|
Python 版本: | 1.5 |