Python 内置函数complex详解,pythoncomplex

英文文档:

class complex([real[, imag]])

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.

说明:

1. 函数功能,返回一个复数。有两个可选参数。

2. 当两个参数都不提供时,返回复数 0j。

>>> complex()

0j

3. 当第一个参数为字符串时,调用时不能提供第二个参数。此时字符串参数,需是一个能表示复数的字符串,而且加号或者减号左右不能出现空格。

>>> complex('1+2j',2) #第一个参数为字符串,不能接受第二个参数

Traceback (most recent call last):

File "", line 1, in

complex('1+2j',2)

TypeError: complex() can't take second arg if first is a string

>>> complex('1 + 2j') #不能有空格

Traceback (most recent call last):

File "", line 1, in

complex('1 + 2j')

ValueError: complex() arg is a malformed string

4. 当第一个参数为int或者float时,第二个参数可为空,表示虚部为0;如果提供第二个参数,第二个参数也需为int或者float。

>>> complex(2)

(2+0j)

>>> complex(2.1,-3.4)

(2.1-3.4j)

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

python中的complex是什么意思_Python 内置函数complex详解,pythoncomplex相关推荐

  1. python int函数详解_Python内置函数OCT详解

    英文文档:oct ( x ) Convert an integer number to an octal string. The result is a valid Python expression ...

  2. python中dir用法_Python内置函数dir详解

    1.命令介绍 最近学习并使用了一个python的内置函数dir,首先help一下: >>> help(dir) Help on built-in function dir in mo ...

  3. python中求包含5的数_Python 内置函数 ( ) 可以返回列表、元组、字典、集合、字符串以及 range 对象中元素个数。_学小易找答案...

    [简答题]实例1:求两数相除的结果. 先后输入2个数据,计算第一个数除以第二个数的结果. 要求能够处理输入数据为非数字.除数为零.文件末尾EndOfFile 和用户使用Ctrl + C 命令终止程序等 ...

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

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

  5. python 作用域从大到小排序_Python 内置函数、作用域、闭包、递归

    一.内置函数如何使用 help()一下: 如想看min()咋用?在shell中:help(min) 二.部分内置函数 (一).排序:sorted() li = [(1, 2, 3, 4), (7, 8 ...

  6. Python中冷门但非常好用的内置函数

    Python中有许多内置函数,不像print.len那么广为人知,但它们的功能却异常强大,用好了可以大大提高代码效率,同时提升代码的简洁度,增强可阅读性 Counter collections在pyt ...

  7. 【Python入门】Python 63个内置函数超级详解

    Python内置了一些非常精巧且强大的函数,对初学者来说,一般不怎么用到,但是偶尔会碰到,我也是用了一段时间python之后才发现,卧槽,还有这么好的函数,每个函数都非常经典,而且经过严格测试,使用内 ...

  8. Python 63个内置函数超级详解

    python内置了一些非常精巧且强大的函数,对初学者来说,一般不怎么用到,但是偶尔会碰到,我也是用了一段时间python之后才发现,卧槽,还有这么好的函数,每个函数都非常经典,而且经过严格测试,使用内 ...

  9. Python 63个内置函数超级详解!这63个必会!

    python内置了一些非常精巧且强大的函数,对初学者来说,一般不怎么用到,但是偶尔会碰到,我也是用了一段时间python之后才发现,卧槽,还有这么好的函数,每个函数都非常经典,而且经过严格测试,使用内 ...

最新文章

  1. SpringMVC @autowrid注入空指针
  2. python函数def里面嵌套def,python菜鸟求问关于嵌套函数中作用域范围应该怎么理解?,python嵌套,直接上代码def l(l...
  3. SAP Cloud for Customer Price-计价简介
  4. 论文笔记:ZFNet
  5. PowerShell自动删除过期数据
  6. 用squid配置代理服务器(基于Ubuntu Server 12.04)
  7. [转]Flex与.NET互操作(三):基于WebService的数据访问(下)
  8. java getchildren用法_Java ZkClient.getChildren方法代碼示例
  9. python客户端自动化测试滚轮移到最上面_Python+Appium自动化测试(8)-swipe()滑动页面...
  10. 机器学习相关速查表Cheat Sheet
  11. 工作资讯004---多范式编程语言
  12. 深度学习框架排行榜:找工作学TensorFlow,PyTorch搜索量逼近Keras
  13. Linux下rpm安装MySQL及配置
  14. Nginx——Nginx实现服务端集群搭建
  15. 对拍--from Altf4
  16. Ubuntu安装使用Krita
  17. props写法_详解Vue内部怎样处理props选项的多种写法
  18. 解开关于人工智能的六个迷思
  19. RGW Bucket Shard优化
  20. cocos creator 达达麻将(麒麟麻将)运行环境配置

热门文章

  1. java和js中替换字符串的方法
  2. 在我女儿的五个学校作业问题上测试 ChatGPT
  3. 用Python绘制一朵玫瑰花
  4. 对于Imbalance Data的总结
  5. hbck源码系列(四)--表的完整性检查和修复Check
  6. Android架构纵横谈之二——基于性能的考虑(1)
  7. 开放性问题 vs 封闭性问题
  8. linux php 编译安装_linux下编译安装配置php5.6.30过程
  9. 政策效应,基于反事实框架
  10. 日常起居六忌是什么?