Python cmath.sqrt() 方法
示例
求複數的平方根
#匯入 cmath 庫
import cmath
#返回複數的平方根
print (cmath.sqrt(2 + 3j))
print (cmath.sqrt(15))
自己動手試一試 »
定義和用法
cmath.sqrt()
方法返回複數的平方根。
注意: 該數字必須大於或等於 0。
語法
cmath.sqrt(x)
引數值
引數 | 描述 |
---|---|
x | 必需。要查詢平方根的數字。如果數字小於 0,則返回 ValueError。如果值不是數字,則返回 TypeError |
技術詳情
返回值 | 一個 complex 值,表示複數的平方根 |
---|---|
Python 版本 | 1.5 |