• 技术文章 >常见问题 >Python常见问题

    python中复数如何写

    silencementsilencement2020-03-13 20:32:39原创5946

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

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

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

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

    相关文章推荐

    • python判断字符串是否包含数字• python如何过滤数字• python怎么将字符串转换为数字• python里面如何输入数字

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网