• Manual
  • 直译
  • 实例
  • 拓展阅读

Manual

Return a complex number with the value real + imag*1j or convert a string or number to a complex number. If the first parameter is a string, it will be interpreted as a complex number and the function must be called without a second parameter. The second parameter can never be a string. Each argument may be any numeric type (including complex). If imag is omitted, it defaults to zero and the constructor serves as a numeric conversion like int and float. If both arguments are omitted, returns 0j.

Note When converting from a string, the string must not contain whitespace around the central + or - operator. For example, complex('1+2j') is fine, but complex('1 + 2j') raises ValueError.

The complex type is described in Numeric Types — int, float, complex.

直译

以实部+虚部*1j形式返回一个复数,或将字符串或数字转化为复数。如果第一个参数是字符串,它将会被转化为复数,且函数的调用不能有第二个参数,第二个参数永远不能是字符串。每个参数可以使任意数值类型(包括复数)。如果缺省虚部,它默认为0,构造器会以整数或浮点数值进行对待。如果两个参数都缺省,则返回0j。

注意:当从一个字符串转化时,字符串在中间的‘+’或‘-’操作符周围不能包含空格。例如:复数complex('1+2j')可行,但complex('1 + 2j')则会引发ValueError。

复数类型详见数值类型—整数,浮点数和复数

实例

>>> complex(0)
0j
>>> complex(3, 5)
(3+5j)
>>> complex(2.25, 163.33)
(2.25+163.33j)
>>> complex('1+2j')
(1+2j)
>>> complex('1 + 2j')
Traceback (most recent call last):File "<pyshell#144>", line 1, in <module>complex('1 + 2j')
ValueError: complex() arg is a malformed string
>>> complex('1+2j', '6j')
Traceback (most recent call last):File "<pyshell#145>", line 1, in <module>complex('1+2j', '6j')
TypeError: complex() can't take second arg if first is a string

拓展阅读

数值类型—整数,浮点数和复数

Python 内建函数 - complex([real[, imag]])相关推荐

  1. Python内建函数与对象方法

    博客 学院 下载 GitChat 论坛 问答 商城 VIP 活动 招聘 ITeye 码云 CSTO 写博客 发Chat Python内建函数与对象方法 转载 2016年06月16日 22:14:20 ...

  2. python内建函数有哪些_Python内建函数大全(一)

    Python 解释器内置了许多函数和类型,列表如下(按字母排序) abs(x) 返回一个数字的绝对值.参数可以是整数或浮点数.如果参数是一个复数,则返回它的模. all(iterable) 如果 it ...

  3. [转载] python支持complex吗_Python 内置函数complex详解

    参考链接: Python complex() 英文文档: class complex([real[, imag]]) Return a complex number with the value re ...

  4. python内建函数是什么意思_python、什么是内建函数?

    展开全部 python内建函数总结 1. abs(x) abs()函数返回数字2113(可为普通型.长整5261型或浮点型)的绝对值.如果给出复4102数,1653返回值就是该复数的模.例如: > ...

  5. python中complex函数的用法_​Python中complex函数有什么用

    ​Python中complex函数有什么用 发布时间:2020-12-15 09:34:36 来源:亿速云 阅读:71 作者:小新 这篇文章给大家分享的是有关Python中complex函数有什么用的 ...

  6. python中complex函数的用法_Python 内置函数complex详解

    英文文档: class complex([real[, imag]]) Return a complex number with the value real + imag*1j or convert ...

  7. python __builtins__ complex类 (13)

    13.'complex', 函数用于创建一个值为 real + imag * j 的复数或者转化一个字符串或数为复数.如果第一个参数为字符串,则不需要指定第二个参数. class complex(ob ...

  8. Python中复数取.imag的问题

    Python中复数取.imag的问题 Python直接支持复数,给工程计算带来了方便,实际使用中,发现其有些特殊的行为,需要特别注意. 观察下面的例子 >>> 1.23e+4+9.8 ...

  9. Python中complex复数类型的简单介绍

    1 复数的简要描述 虚数由实部和虚部两个部分构成: real+imag(虚部后缀为j或J) 其中实数部分和虚数部分都为浮点数. 例如定义一个虚数,分别输出它的实部和虚部: a=4.7+0.666j # ...

最新文章

  1. ES6,新增数据结构Set的用法
  2. 产品经理入门应该怎样学习和成长?
  3. 数据库(Mysql)背后的数据结构-学习
  4. Spring Boot系列教程四:配置文件详解properties
  5. 突发!王思聪名下房产、汽车、存款等被查封
  6. 新硬盘挂载-fdisk+mount案例实操
  7. 网规之路——强化项目管理知识点训练
  8. matlab cgf sc 未定义,matlab通用神經網絡代碼
  9. Pytest之基本介绍
  10. copy_to_user,copy_from_user,get_user,put_user函数比较
  11. ixigua解析_资本运作系列课程五:《科创板申请上市估值模型理论解析》现场直播回放...
  12. Acer宏基笔记本FN快捷键大全
  13. 方维直播3.1最新搭建文档《0》-原创
  14. 杭州阿里五面全过程:一面技术面+二面(项目+技术)+三面(项目经理面)+四面(地区技术负责人面)...
  15. 单线激光雷达(Lidar)学习三:使用雷达数据/scan转/PointCloud后生成鸟瞰图
  16. java图形界面编程如何给窗口设置背景图片
  17. solidworks中开孔绘制螺纹孔
  18. SVG:linearGradient渐变在直线上失效的问题解决方案
  19. Lattice Diamond关于原语的使用
  20. 开通我的技术博客,和以前关于生活的博客,分开旅行

热门文章

  1. CUDA——线程束分化
  2. 微服务架构(Microservices)
  3. Mac用户学Python-Day1:安装与环境配置
  4. gsensor架构和原理分析
  5. 关于软件测试的基础认知分享
  6. CSS新招式,临时记一下
  7. Excel 表格图片压缩方法
  8. node生成唯一设备id(node-machine-id)
  9. magisk卸载内置软件_手机刷入面具magisk授权后,ROOT权限经常丢失解决方法
  10. 163vip邮箱登录,163邮箱怎么登陆?如何登录163vip邮箱?