Python‎ > ‎Built-in‎ > ‎

complex()

http://www.adilwaseem.com/
Definition
The method convert the float, int, decimal into the complex number.

Syntax
complex(x)

Parameters
x=number

Examples
The return are:
 >>> complex(2562)
(2562+0j)
>>> complex(2255888)
(2255888+0j)
>>> complex(15)
(15+0j)
>>> complex(1552258785)
(1552258785+0j)
>>> complex(100033000030003300000)
(1.000330000300033e+20+0j)
>>> complex('22223144')
(22223144+0j)
>>> complex(15265525877866225888844522)
(1.5265525877866226e+25+0j)
 
complex()__truediv__()
The complex number value obtained through__truediv__:
 >>> complex(2255888+0j).__truediv__(22)
(102540.36363636363+0j)

complex()__str__()
The method convert the complex to string.
 >>> complex(2255888+0j).__str__()
'(2255888+0j)'

complex()__sub__()
The method returns the value.
 >>> complex(2255888+0j).__sub__(22.9)
(2255865.1+0j)

complex()__rpow__()
The method returns complex number value as:
 >>> complex(15+0j).__rpow__(3)
(14348907+0j)

The method returns the value.
 >>> complex(2255888+0j).__sub__(22.9)
(2255865.1+0j)


complex(random.gauss()+random.vonmisesvariate())
The method return with:.
import operator
import random
c=operator.pos(a)
d=operator.pos(b)
f=c+d
list=[1,19,33,31]
g=sum(list)
print(f/g)

>>>
(0.05995071123597758+0j)
>>>

The class method return the complex values and tested the equality of the values.
 class complex_value:
    def __init__(self, a,b,c):

        self.a=complex(a).conjugate()
        self.b=complex(b).imag
        self.c=complex(c).real

        print("The comlex conjugate value of a is: ",self.a)
        print("The complex imag value of b is: ",self.b)
        print("The complex  real value of c is: ",self.c)
        
        if self.a.__eq__(complex(a).conjugate()):
            print("The value of a is equal to complex(a) conjugate")
        else:
             print("The value of a is NOT equal to complex(a) conjugate")
            

        if self.b.__eq__(complex(b).imag):
            print("The value of b is equal to complex(b) imag")
        else:
            print("The value of b is NOT equal to complex(b) imag")


        if self.c.__eq__(complex(c).real):
            print("The value of c is equal to complex(c) imag")
        else:
            print("The value of c is NOT equal to complex(c) imag")

           
value1=81
value2=222
value3=33
complex_value(value1,value2, value3)

>>> 
The comlex conjugate value of a is: (81-0j)
The complex imag value of b is: 0.0
The complex real value of c is: 33.0
The value of a is equal to complex(a) conjugate
The value of b is equal to complex(b) imag
The value of c is equal to complex(c) imag
>>>

Comments