• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python 内置函数complex详解

Python 内置函数complex详解

作者:lqh 字体:[增加 减小] 来源:互联网

lqh 通过本文主要向大家介绍了python complex,python中complex,complex函数,matlab complex函数,matlab中complex函数等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

英文文档:

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
 
</div>

  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

</div>

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

>>> complex(2)
(2+0j)
>>> complex(2.1,-3.4)
(2.1-3.4j)
 
</div>

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

</div>

您可能想查找下面的文章:

  • Python 内置函数complex详解
  • Python标准库内置函数complex介绍

相关文章

  • python使用win32com库播放mp3文件的方法
  • 轻松实现python搭建微信公众平台
  • python 将字符串转换成字典dict
  • Linux下为不同版本python安装第三方库
  • 浅谈Tensorflow 动态双向RNN的输出问题
  • Python命名空间详解
  • 在Python中使用dict和set方法的教程
  • python ElementTree 基本读操作示例
  • 使用Python中的tkinter模块作图的方法
  • python基础教程之lambda表达式使用方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python进程类subprocess的一些操作方法例子
    • python类装饰器用法实例
    • 使用Python的PIL模块来进行图片对比
    • 在Django中创建第一个静态视图
    • Python利用Nagios增加微信报警通知的功能
    • python生成式的send()方法(详解)
    • Python自动重试HTTP连接装饰器
    • python实现自动登录人人网并采集信息的方法
    • Python计算已经过去多少个周末的方法
    • Python随机生成彩票号码的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有