Python Program to Multiply Two Complex Numbers

A complex number is represented by a + bi or a + bj. Python handles complex numbers using complex data types. Python uses a+bj notation. Python programming language converts the real numbers a and b into complex using the function complex(a,b).

In python, we can set complex number using a = 3 + 5j. After setting like this we can access real part of a can be obtained using a.real and imaginary part of a can be obtained using b.imag.


>>> a=3+4j
>>> a.real
>>> a.imag
>>> complex(1,2)

Python handles simple operation like addition, subtraction, multiplication and division directly. For more advanced operation on complex numbers you can use cmath library.

Multiplication of Two Complex Numbers in Python

# Python program to multiply two complex number

# Enter first complex number i.e. 3+4j not 3+4i
first = complex(input('Enter first complex number: '))
second = complex(input('Enter first complex number: '))

# Multiplication of complex number
product = first * second

# Displaying Sum
print('PRODUCT = ', product)

Output of Above Program

Enter first complex number: 2+3j
Enter first complex number: 4+6j
PRODUCT =  (-10+24j)