欢迎光临
我们一直在努力

九八云Python教程:python中复数如何写

Python可以支持复数,复数的虚部用 j 或 J 来表示。

下面展示复数的写法和用法:

ac1 = 3 + 0.2j
print (ac1)
print(type(ac1)) #输出复数类型
ac2 = 4 - 0.1j
print(ac2)
#复数运行
print(ac1 + ac2) #输出(7+0.1j)
#导入cmath 模块
import cmath
#sqrt()是cmath 模块下的商数,用于计算平方根
ac3 = cmath.sqrt(-1)
print (ac3) #输出1j

推荐:Python教程。

未经允许不得转载:九八云安全 » 九八云Python教程:python中复数如何写