Python program for addition and subtraction of complex numbers Last Updated : 16 May, 2023 Comments Improve Suggest changes Like Article Like Report 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 Example : Python3 # 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( "Addition is : ", addComplex(z1, z2)) Output: Addition is : (3+5j) Time Complexity: O(1) Auxiliary Space: O(1) 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 Example : Python3 # Python program to subtract # two complex numbers # function that returns # a complex number after # subtracting def subComplex( z1, z2): return z1-z2 # driver program z1 = complex(2, 3) z2 = complex(1, 2) print( "Subtraction is : ", subComplex(z1, z2)) Output: Subtraction is : (1+1j) Time Complexity: O(1) Auxiliary Space: O(1) Approach#3: Using to different functionsAlgorithm 1.Read the two complex numbers from the user.2.Define a function to add two complex numbers.3.Define a function to subtract two complex numbers.4.Call the two functions with the two complex numbers as arguments.5.Print the results. Python3 # Define a function to add two complex numbers def complex_addition(num1, num2): return num1 + num2 # Define a function to subtract two complex numbers def complex_subtraction(num1, num2): return num1 - num2 # Read the two complex numbers from the user num1 = complex(2, 3) num2 = complex(1, 2) # Call the two functions with the two complex numbers as arguments addition = complex_addition(num1, num2) subtraction = complex_subtraction(num1, num2) # Print the results print("Addition is :", addition) print("Subtraction is :", subtraction) OutputAddition is : (3+5j) Subtraction is : (1+1j) Time Complexity: O(1) (constant time complexity for addition and subtraction of complex numbers)Auxiliary Space: O(1) (constant space complexity as we are using only two variables) Comment More infoAdvertise with us Next Article Python program for addition and subtraction of complex numbers A ankitkumar34 Follow Improve Article Tags : Technical Scripter Python Python Programs Technical Scripter 2019 python-utility +1 More Practice Tags : python Similar Reads Python Program to convert complex numbers to Polar coordinates Before starting with the program, let's see the basics of Polar Coordinates and then use Python's cmath and abs module to convert it. Polar coordinates are just a different way of representing Cartesian coordinates or Complex Numbers. A complex number z is defined as : z=x+yj It is completely determ 4 min read Subtract Two Numbers in Python Subtracting two numbers in Python is a basic operation where we take two numeric values and subtract one from the other. For example, given the numbers a = 10 and b = 5, the result of a - b would be 5. Let's explore different methods to do this efficiently.Using Minus Operator (-)This is the most st 2 min read Python program to Return the real part of the complex argument Given a complex number, the task is to write a Python Program to return the real part of the complex argument. What is a Complex number? Complex numbers are those numbers that are written in the format a+ib, where 'a' and 'b' are real numbers and 'i' is the imaginary part called "iota." (â-1)  is th 2 min read How to Add Two Numbers in Python The task of adding two numbers in Python involves taking two input values and computing their sum using various techniques . For example, if a = 5 and b = 7 then after addition, the result will be 12.Using the "+" Operator+ operator is the simplest and most direct way to add two numbers . It perform 4 min read Working with Negative Numbers in Python Negative numbers play a crucial role in various mathematical and programming scenarios. In Python, handling negative numbers is a fundamental skill for developers. In this article, we will explore some commonly used methods for working with negative numbers in Python, along with examples to illustra 3 min read Like