Python program to subtract two complex numbers

Here in this context, we are going to learn about the Python program to subtract two complex numbers.

A complex number is created from two real numbers. Python complex number can be created using two methods first is the complex() function and another is using a direct assignment statement. Complex numbers are mostly used where we define something using two real numbers.

This program is going to be simple enough as Python can handle complex numbers easily. Thanks to Python.

We will start with the very basic.

Creating complex numbers in Python:

complexno = 8 + 3j
print(type(complexno))
print(complexno)
<class 'complex'>
(8+3j)
complexno = complex(8, 3)
print(type(complexno))
print(complexno)
<class 'complex'> 
(8+3j)

Subtract two complex numbers in Python:

complexno = 3 + 7j
complexno1 = 1 + 14j
print('Subtraction of two complex number=', complexno - complexno1)

Output:

Subtraction of two complex number=2-7j

Here we have initialized two complex numbers and then subtracting that number we get the output. We can also take input from the user using the input() method and then subtract it.

Also, learn:

Leave a Reply

Your email address will not be published. Required fields are marked *