后浪云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教程。
版权声明:
作者:后浪云
链接:https://idc.net/help/181993/
文章版权归作者所有,未经允许请勿转载。
THE END
