1、数学中复数有a+bi表示,python中复数是由一个实数和一个虚数组合构成,表示为:x+yj一个复数有一对有序浮点数 (x,y),其中 x 是实数部分,y 是虚数部分。
2、我们可以通过help(a)命令来查看复数的帮助文档。Help on complex object:class complex(object)| complex(real[, imag]) -> complex number|| Create a complex number from a real part and an optional imaginary part.| This is equivalent to (real + imag*1j) where imag defaults to 0.|| Methods defined here:
3、我们通过dir(a)命令,发现复数有这些属性。['__abs__', '__add__', '__bool__媪青怍牙', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__int__', '__le__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__pos__', '__pow__', '__radd__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rmod__', '__rmul__', '__rpow__', '__rsub__', '__rtruediv__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', 'conjugate', 'imag', 'real']
4、复数的第一个属性是模,也是绝对值abs(),这里abs(a)和a.__abs__()是等效的。我们对a取模,没有改变a。
5、同样复数的__add__()属性也不会改变a的值,a.__add__(x)会返回a和x的和。注意x为一个单位的虚值时不能写成j(这样j就是一个变量),而要写成1j。
6、复数的内建属性:复数对象拥有数据属性,分别为该复数的实部和虚部。复数还拥有 conjugate 方法,调用它可以返回该复数的共轭复数对象。复数属性:real(复数的实部)、imag(复数的虚部)、conjugate()(返回复数的共轭复数)复数还有很多其它内部属性,我们以后慢慢学习。