Python 内置函数complex详解
2016-10-23 00:00
609 查看
英文文档:
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。
3. 当第一个参数为字符串时,调用时不能提供第二个参数。此时字符串参数,需是一个能表示复数的字符串,而且加号或者减号左右不能出现空格。
4. 当第一个参数为int或者float时,第二个参数可为空,表示虚部为0;如果提供第二个参数,第二个参数也需为int或者float。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
Python标准库内置函数complex介绍
windows下ipython的安装与使用详解
Python做文本按行去重的实现方法
Python首次安装后运行报错(0xc000007b)的解决方法
python类中super()和__init__()的区别
Python 序列的方法总结
python 异常处理总结
python 队列详解及实例代码
python中os模块详解
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 "<pyshell#2>", line 1, in <module> 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 "<pyshell#3>", line 1, in <module> 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 四种数值类型(int,long,float,complex)Python标准库内置函数complex介绍
windows下ipython的安装与使用详解
Python做文本按行去重的实现方法
Python首次安装后运行报错(0xc000007b)的解决方法
python类中super()和__init__()的区别
Python 序列的方法总结
python 异常处理总结
python 队列详解及实例代码
python中os模块详解
相关文章推荐
- Python 将类的对象转换成 JSON 详解 - [开发]
- 《简明 Python 教程》中第十五章例子详解
- Python and django(四)--详解python中的数字和序列
- python time模块详解
- 快速部署Python应用:Nginx+uWSGI配置详解
- python 内建函数详解及相关示例
- Python嵌入C++详解(1)--HelloWorld
- Python天天美味(34) - Decorators详解
- Pamie模块详解 python操作ie浏览器
- Python计时相关操作详解【time,datetime】
- Python嵌入C++详解(1)--HelloWorld
- Python库详解之网络(2)--解析网页
- Python and django(四)--详解python中的数字和序列
- Python嵌入C++详解(2)--Import Module
- Python模块详解
- python中的新型类及其实例详解
- 详解Python3.1版本带来的核心变化
- Python 字符串方法详解
- Python连接以及操作MySQL数据库详解
- Python 递归处理文件和文件夹代码详解