python支持complex吗_Python 内置函数complex详解

英文文档:

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函数详解 Python complex函数

本文原创发布php教程 ,转载请注明出处,感谢您的尊重!

上一篇:Python首次安装后运行报错(0xc000007b)的解决方法

下一篇:Python判断某个用户对某个文件的权限

相关文章

相关视频

在Django框架中运行Python应用全攻略

在Python的Django框架中创建和使用模版

python获取元素在数组中索引号的方法

浅谈python中截取字符函数strip,lstr...

Python 内置函数complex详解

Python 简介

Python 环境搭建

Python 中文编码

Python 基础语法

Python 变量类型

网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论

立即提交

专题推荐

独孤九贱-php全栈开发教程

全栈 100W+

主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门

玉女心经-web前端开发教程

入门 50W+

主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门

天龙八部-实战开发教程

实战 80W+

主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习

作者信息

php教程

认证0级讲师

最近文章

发布技术文章

最新文章

热门排行

python之禅怎么打出来

python怎么学

boosting和bootstrap区别

python库是什么意思

python卸载后怎么也安装不上

python安装后怎么不见了

python怎么卸载模块

python能做什么?是什么?

pickle库的使用详解

Anaconda的新手使用大全

python爬虫是什么?为什么把python叫做爬虫?

Python微信库:itchat的用法详解

关于python3学习基础知识总结

python爬虫是什么

使用Python可以做什么

python如何实现可视化热力图

推荐视频教程

javascript初级视频教程

jquery 基础视频教程

视频教程分类

php视频教程

html视频教程

css视频教程

JS视频教程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值