A complex number is composed of a real part and an imaginary part, represented as:x+yj

A complex number is a pair of ordered floating-point numbers (x,y), where x is the real part and y is the imaginary part.

Concepts about complex numbers in Python:

1. Imaginary numbers cannot exist alone; they always combine with a real part with a value of 0.0 to form a complex number

2. A complex number consists of a real part and an imaginary part

3. Syntax for representing imaginary numbers:real+imagej

4. Both the real part and the imaginary part are floating-point numbers

5. The imaginary part must have the suffix j or J

#coding=utf8

aa=123-12j
print aa.real  # output 实数部分 123.0  
print aa.imag  # output虚数部分 -12.0

Output result:

123.0
-12.0

Built-in attributes of complex numbers:

Complex number objects have data attributes, which are the real part and the imaginary part of the complex number respectively.

Complex numbers also have the conjugate method, which can be called to return the conjugate complex number object of the complex number.

Complex number attributes: real (the real part of the complex number), imag (the imaginary part of the complex number), conjugate() (returns the conjugate complex number of the complex number)

#coding=utf8

class Complex(object):
    '''创建一个静态属性用来记录类版本号'''
    version=1.0
    '''创建个复数类,用于操作和初始化复数'''
    def __init__(self,rel=15,img=15j):
        self.realPart=rel
        self.imagPart=img
       
    #创建复数
    def creatComplex(self):
        return self.realPart+self.imagPart
    #获取输入数字部分的虚部
    def getImg(self):
        #把虚部转换成字符串
        img=str(self.imagPart)
        #对字符串进行切片操作获取数字部分
        img=img[:-1] 
        return float(img)  
                       
def test():
    print "run test..........."
    com=Complex()
    Cplex= com.creatComplex()
    if Cplex.imag==com.getImg():
        print com.getImg()
    else:
        pass
    if Cplex.real==com.realPart:
        print com.realPart
    else:
        pass
    #原复数
    print "the religion complex is :",Cplex
    #求取共轭复数
    print "the conjugate complex is :",Cplex.conjugate()
    
if __name__=="__main__":
    test()

Reference documentation: https://blog.csdn.net/henni_719/article/details/56665254