python中的complex()函数
python中的complex()函数
1. complex()函数用于创建一个复数或者将一个数或字符串转换为复数形式,其返回值为一个复数。该函数的语法为:
Help on class complex in module builtins:class complex(object)| complex(real=0, imag=0)| | Create a complex number from a real part and an optional imaginary part.#image默认为0| | This is equivalent to (real + imag*1j) where imag defaults to 0.| | Methods defined here:| | __abs__(self, /)| abs(self)| | __add__(self, value, /)| Return self+value.| | __bool__(self, /)| self != 0| | __divmod__(self, value, /)| Return divmod(self, value).| | __eq__(self, value, /)| Return self==value.| | __float__(self, /)| float(self)| | __floordiv__(self, value, /)| Return self//value.| | __format__(...)| complex.__format__() -> str| | Convert to a string according to format_spec.| | __ge__(self, value, /)| Return self>=value.| | __getattribute__(self, name, /)| Return getattr(self, name).| | __getnewargs__(...)| | __gt__(self, value, /)| Return self>value.| | __hash__(self, /)| Return hash(self).| | __int__(self, /)| int(self)| | __le__(self, value, /)| Return self<=value.| | __lt__(self, value, /)| Return self<value.| | __mod__(self, value, /)| Return self%value.| | __mul__(self, value, /)| Return self*value.| | __ne__(self, value, /)| Return self!=value.| | __neg__(self, /)| -self| | __pos__(self, /)| +self| | __pow__(self, value, mod=None, /)| Return pow(self, value, mod).| | __radd__(self, value, /)| Return value+self.| | __rdivmod__(self, value, /)| Return divmod(value, self).| | __repr__(self, /)| Return repr(self).| | __rfloordiv__(self, value, /)| Return value//self.| | __rmod__(self, value, /)| Return value%self.| | __rmul__(self, value, /)| Return value*self.| | __rpow__(self, value, mod=None, /)| Return pow(value, self, mod).| | __rsub__(self, value, /)| Return value-self.| | __rtruediv__(self, value, /)| Return value/self.| | __str__(self, /)| Return str(self).| | __sub__(self, value, /)| Return self-value.| | __truediv__(self, value, /)| Return self/value.| | conjugate(...)| complex.conjugate() -> complex| Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j.| ----------------------------------------------------------------------| Static methods defined here:| __new__(*args, **kwargs) from builtins.type| Create and return a new object. See help(type) for accurate signature.| ----------------------------------------------------------------------| Data descriptors defined here:| imag| the imaginary part of a complex number| real| the real part of a complex number>>>
2.简单的使用方法
>>> a = complex(6,8)
>>> a
(6+8j)
>>> print(a.real)
6.0
>>> print(a.imag)
8.0
>>> print(a.conjugate())
(6-8j)
3. complex(real, imag)参数可使用的数据类型
real可以为int、long、float或字符串类型;而image只能为int、long、或float类型
- 注意:如果第一个参数为字符串,第二个参数必须省略,若第一个参数为其他类型,则第二个参数可以选择
>>> complex('1',6)
Traceback (most recent call last):File "<pyshell#0>", line 1, in <module>complex('1',6)
TypeError: complex() can't take second arg if first is a string
python中的complex()函数相关推荐
- Python中的常用函数
1.range()是一个函数 for i in range () 就是给i赋值: 比如 for i in range (1,3): 就是把1,2依次赋值给i range () 函数的使用是这样的: r ...
- python中的pop()函数和popleft()函数
python中的pop()函数和popleft()函数 首先对于pop而言,它是用于stack中的: stack = [1, 2, 3, 4] print(stack) stack.append(6) ...
- python中使用zip函数基于两个列表数据list创建字典dict数据(Create a dictionary by passing the output of zip to dict)
python中使用zip函数基于两个列表数据list创建字典dict数据(Create a dictionary by passing the output of zip to dict) 目录
- python中add函数_如何使用python中的add函数?
之前向大家介绍过python中的求和函数sum函数,numpy中的sum函数,对于数组可以指定维度进行相加.numpy中还有另一种求和运算方法,即add函数.add函数不仅作用于numpy中加法运算, ...
- python 2: 解决python中的plot函数的图例legend不能显示中文问题
python 2: 解决python中的plot函数的图例legend不能显示中文问题 参考文章: (1)python 2: 解决python中的plot函数的图例legend不能显示中文问题 (2) ...
- python中list作为函数参数_在python中list作函数形参,防止被实参修改的实现方法
0.摘要 我们将一个list传入函数后,函数内部对实参修改后,形参也会随之改变.本文将主要介绍这种错误的现象.原因和解决方法. 1.代码示例 def fun(inner_lst): inner_lst ...
- Python中的map()函数和reduce()函数的用法
Python中的map()函数和reduce()函数的用法 这篇文章主要介绍了Python中的map()函数和reduce()函数的用法,代码基于Python2.x版本,需要的朋友可以参考下
- python input与返回值-python中使用input()函数获取用户输入值方式
我们编写程序最终目的还是来解决实际问题,所以必然会遇到输入输出的交互问题,python中提供了input函数用来获取用户的输入,我们可以用以下程序演示. user_gender = input(&qu ...
- Python中的sorted函数以及operator.itemgetter函数
from:Python中的sorted函数以及operator.itemgetter函数 operator.itemgetter函数 operator模块提供的itemgetter函数用于获取对象的哪 ...
- python中怎么做分组问题_详解Python中的分组函数groupby和itertools)
具体代码如下所示: from operator import itemgetter #itemgetter用来去dict中的key,省去了使用lambda函数 from itertools impor ...
最新文章
- 解题报告:CF1307D Cow and Fields(最短路、最优解不等式化简)
- innodb表 手工导入导出
- 《BREW进阶与精通——3G移动增值业务的运营、定制与开发》连载之76——BREW中的安全性网络编程...
- 【推荐系统】一文梳理联邦学习推荐系统研究进展
- Solaris的硬件相关命令
- CentOS 6.5 安装配置Tomcat7服务器
- 7-1 多数组排序 (12 分)三种做法(冒泡排序 ; 重写sort方法 ;利用sort和栈)
- 苹果 iPhone/iPad 第三方键盘为何没语音听写功能?真相了
- 【CVPR 2021联邦学习论文解读】Model-Contrastive Federated Learning (MOON) 联邦学习撞上对比学习
- Thinkpad SL400开启蓝牙
- PhotoShop软件笔记
- 记一次网站服务器搬迁实录
- JSP基于web网上作业提交系统
- Java基础面试题(持续更新...)
- Unity [hold on busy for 老长长时间的解决方法]
- 网站优化和SEO的差别
- HDU 6187 Destroy Walls
- arduino编乐谱_【Arduino】用Arduino编首小曲子吧
- 0-1000随机自然数生成
- python怎么算二元一次方程_使用 Python 解数学方程
热门文章
- 关乎未来40年企业生存,这些食品饮料巨头都在干这件事儿! | 商研局 Cool Business...
- 服务器多个网站对应多个域名,多个域名指向同一个网站怎么样设置更合理?
- python判断火车票座位号分布图_如何选择火车靠窗座位和选座位技巧!
- excel公式编辑器_巧用Excel制作炫酷聚光灯效果,数据查看太方便了
- pcsx2解决竖线问题:
- 5316. 竖直打印单词(print-words-vertically)
- Diskpart 实现分区自动化
- SICP 第二章的练习
- Android kotlin 系列讲解(基础篇) Any和Any?
- 复杂边坡的ansys三维建模