发布时间:2022-07-07 09:40:25 人气:286 作者:多测师
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相关知识,请关注多测师。https://www.e70w.com/xwzx/