问Python中可以表示复数吗?

答 1 个回答|247 次阅读
Coco老师 - 官方公众号:青少儿编程学习网
擅长:编程教育网站:https://kidscodes.cn/

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最适合青少儿进阶学习的编程语言