When I first started working with complex numbers in Python, I was building a data-processing tool for an electrical engineering project in California. The task involved analyzing alternating current (AC) signals, which naturally required handling complex values for impedance and voltage.
At that time, I realized how powerful Python is when it comes to mathematical operations, especially with complex numbers. Python makes it incredibly easy to perform arithmetic operations like addition, subtraction, and multiplication on complex numbers.
In this tutorial, I’ll share three simple and effective methods to add complex numbers in Python. I’ll also explain how each method works, when to use it, and why Python’s built-in support for complex numbers is one of its hidden gems.
What Are Complex Numbers in Python?
Before we start adding complex numbers, let’s quickly understand what complex numbers are in Python.
A complex number has two parts, a real part and an imaginary part. It’s usually written in the form a + bj, where a is the real part and b is the imaginary part.
In Python, complex numbers are represented using the built-in complex data type. You can create a complex number simply by typing something like 3 + 4j.
Here’s a quick example:
# Creating a complex number in Python
z = 3 + 4j
print("Complex Number:", z)
print("Real Part:", z.real)
print("Imaginary Part:", z.imag)This code prints the complex number and its components separately. Python automatically handles the real and imaginary parts for you.
Method 1 – Add Complex Numbers Using the + Operator
When I’m working on quick calculations, I prefer using the + operator to add complex numbers. It’s the simplest and most readable way to do it in Python.
Here’s how it works:
# Define two complex numbers
num1 = 5 + 3j
num2 = 2 + 7j
# Add the two complex numbers
result = num1 + num2
# Display the result
print("First complex number:", num1)
print("Second complex number:", num2)
print("Sum of complex numbers:", result)When you run this code, Python automatically adds both the real and imaginary parts:
First complex number: (5+3j)
Second complex number: (2+7j)
Sum of complex numbers: (7+10j)You can refer to the screenshot below to see the output.

This method is perfect when you’re dealing with simple arithmetic or working on small scripts where readability matters most.
Method 2 – Add Complex Numbers Using the complex() Function
Sometimes, I receive numeric data from sensors or CSV files where the real and imaginary parts are stored separately. In such cases, I use the complex() function to create complex numbers dynamically.
The complex() function takes two arguments, the real and imaginary parts, and returns a complex number.
Here’s how you can use it:
# Create complex numbers using real and imaginary parts
num1 = complex(4, 5)
num2 = complex(6, 2)
# Add them
result = num1 + num2
# Display the result
print("First complex number:", num1)
print("Second complex number:", num2)
print("Sum of complex numbers:", result)Output:
First complex number: (4+5j)
Second complex number: (6+2j)
Sum of complex numbers: (10+7j)You can refer to the screenshot below to see the output.

This method is especially useful when you’re dealing with data-driven applications or scientific computations where real and imaginary parts are stored separately.
Method 3 – Add Complex Numbers Using a Python Function
When I’m working on large projects or need to add multiple complex numbers repeatedly, I prefer creating a reusable function. This keeps my code clean and modular.
Let’s write a simple Python function to add two complex numbers.
def add_complex_numbers(c1, c2):
"""Return the sum of two complex numbers."""
return c1 + c2
# Example usage
num1 = 8 + 2j
num2 = 3 + 9j
result = add_complex_numbers(num1, num2)
print("Complex Number 1:", num1)
print("Complex Number 2:", num2)
print("Sum:", result)Output:
Complex Number 1: (8+2j)
Complex Number 2: (3+9j)
Sum: (11+11j)You can refer to the screenshot below to see the output.

This approach is great when you want to make your code reusable and maintainable, something.
Method 4 – Add Complex Numbers Using NumPy
If you’re working in data science, engineering, or signal processing, chances are you’re already using NumPy. NumPy provides efficient ways to handle complex numbers, especially when you’re dealing with large arrays.
Here’s how you can add complex numbers using NumPy:
import numpy as np
# Create NumPy arrays of complex numbers
arr1 = np.array([2 + 3j, 4 + 5j, 6 + 7j])
arr2 = np.array([1 + 2j, 3 + 4j, 5 + 6j])
# Add them element-wise
result = arr1 + arr2
print("Array 1:", arr1)
print("Array 2:", arr2)
print("Sum of arrays:", result)Output:
Array 1: [2.+3.j 4.+5.j 6.+7.j]
Array 2: [1.+2.j 3.+4.j 5.+6.j]
Sum of arrays: [3. +5.j 7. +9.j 11.+13.j]This method is ideal when you need to perform vectorized operations on large datasets. It’s fast, efficient, and widely used in scientific computing.
Bonus Tip – Extract Real and Imaginary Parts After Addition
After adding complex numbers, you might want to extract their real and imaginary parts separately. Python makes this easy using .real and .imag attributes.
Here’s an example:
num1 = 3 + 5j
num2 = 7 + 2j
result = num1 + num2
print("Sum:", result)
print("Real part:", result.real)
print("Imaginary part:", result.imag)Output:
Sum: (10+7j)
Real part: 10.0
Imaginary part: 7.0This feature is particularly useful when you need to perform further analysis or visualization on individual components of a complex number.
Real-World Example: Add Complex Impedances in Python
Let’s look at a practical example from electrical engineering, calculating the total impedance in a circuit.
In AC circuits, impedances are often represented as complex numbers. When components are connected in series, their impedances simply add up.
Here’s how you can calculate it in Python:
# Impedances of individual components
Z1 = complex(10, 5) # Resistor + Inductor
Z2 = complex(4, -3) # Resistor + Capacitor
Z3 = complex(6, 8) # Another R-L component
# Total impedance in series
Z_total = Z1 + Z2 + Z3
print("Impedance 1:", Z1)
print("Impedance 2:", Z2)
print("Impedance 3:", Z3)
print("Total Impedance:", Z_total)Output:
Impedance 1: (10+5j)
Impedance 2: (4-3j)
Impedance 3: (6+8j)
Total Impedance: (20+10j)This example shows how Python can simplify real-world engineering problems with just a few lines of code.
Common Mistakes to Avoid
Even though Python makes handling complex numbers easy, here are a few mistakes I’ve seen beginners make:
- Using i instead of j — In Python, the imaginary part uses j, not i.
- Mixing data types — Don’t try to add a complex number with a string or list directly.
- Forgetting parentheses — Always use parentheses when defining complex numbers like (3 + 4j).
Avoiding these small mistakes can save you a lot of debugging time.
Adding complex numbers in Python is easy once you understand the basics. Whether you’re using the + operator, the complex() function, a user-defined function, or NumPy arrays, Python gives you flexibility and simplicity.
I’ve used these methods in real-world projects ranging from electrical circuit modeling to signal processing and data visualization. The best part is, Python handles all the heavy lifting for you.
You may also like to read other tutorials on Python:
- Copy a Dictionary in Python
- Check if Python Dictionary is Empty
- Python Dictionary Comprehension
- KeyError in a Nested Python Dictionary

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.