Given two complex numbers z1 and z2. The task is to add and subtract the given complex numbers.
Addition of complex number: In Python, complex numbers can be added using + operator.
Examples:
Input: 2+3i, 4+5i Output: Addition is : 6+8i Input: 2+3i, 1+2i Output: Addition is : 3+5i
# Python program to add # two complex numbers # function that returns # a complex number after # adding def addComplex( z1, z2): return z1 + z2 # Driver's code z1 = complex(2, 3) z2 = complex(1, 2) print( "Addtion is : ", addComplex(z1, z2)) |
chevron_right
filter_none
Output:
Addtion is : (3+5j)
Subtraction of complex numbers: Complex numbers in Python can be subtracted using - operator.
Examples:
Input: 2+3i, 4+5i Output: Subtraction is : -2-2i Input: 2+3i, 1+2i Output: Subtraction is : 1+1i
# Python program to subtract # two complex numbers # function that returns # a complex number after # subracting def subComplex( z1, z2): return z1-z2 # driver program z1 = complex(2, 3) z2 = complex(1, 2) print( "Subtraction is : ", subComplex(z1, z2)) |
chevron_right
filter_none
Output:
Subtraction is : (1+1j)
Recommended Posts:
- Program to Add Two Complex Numbers
- Python program for multiplication and division of complex number
- Python | Subtraction of dictionaries
- Python | How to get Subtraction of tuples
- Python | Mutual tuple subtraction in list
- Python | Nth tuple index Subtraction by K
- Python | Nested Tuples Subtraction
- Background Subtraction in an Image using Concept of Running Average
- Background subtraction - OpenCV
- Python | Addition of tuples
- Addition in Nested Tuples - Python
- Python - Pairwise Addition in Tuples
- Python | Rear Addition of Record
- Python - Specific Range Addition in List
- Python - Diagonal element addition among lists
- Python | Alternate character addition
- Python - Row-wise element Addition in Tuple Matrix
- Python program to check if the list contains three consecutive common numbers in Python
- Python program to count Even and Odd numbers in a List
- Python program to count positive and negative numbers in a list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

