英文文档:
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)
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- s14全球总决赛瑞士轮赛制是什么 全球总决赛瑞士轮赛制详情
- 《COD21》全新剧情宣传片:10月25日XGP见!
- 美国拳王家门口身中7枪遇害 年仅31岁凶手仍未被逮捕
- 《寂静岭2》重制版光追对比:氛围更加恐怖
- 林慧萍.1982-往昔(飞跃复刻版)【歌林】【WAV+CUE】
- 陈楚生.2007-原来我一直都不孤单(EP)【天娱传媒】【WAV+CUE】
- 罗嘉良.1986-秦始皇(2014环球复黑王·百代篇)【EMI百代】【WAV+CUE】
- 2024周年庆赠送物品介绍,周年庆送什么
- 【原神】V5.0攻略 |「明黄曜石断片」全收集
- 【原神】V5.0攻略 | 隐藏成就「烦请高抬贵脚」达成
- 证声音乐图书馆《蔚蓝海岸·爵士度假日》[FLAC/分轨][155.47MB]
- 腾讯音乐人《浪漫火焰(新势力计划合辑 Vol.11)》[320K/MP3][56.91MB]
- 腾讯音乐人《浪漫火焰(新势力计划合辑 Vol.11)[FLAC/分轨][147.45MB]
- 2024年,哪里还可以玩有趣的魔兽RPG?
- 类银河恶魔城动作游戏《灵魂熔解》已正式登陆Steam