您现在的位置是:课程教程文章

python中复数如何写

2023-12-18 19:31课程教程文章 人已围观

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怎么给函数传参

下一篇:没有了

站点信息

  • 文章统计篇文章