Recently, I was working on a Python project where I needed to add two integers, but without using the + or – operators.
At first, it sounded like a strange requirement, but it turned out to be a fun challenge that deepened my understanding of how computers actually perform addition at the binary level.
In this tutorial, I’ll show you how to add two numbers in Python without using arithmetic operators. I’ll walk you through multiple methods, including bitwise operations, recursion, and loop-based logic.
Sum of Two Numbers without Using Arithmetic Operators in Python
To find the sum of two numbers without using arithmetic operators, Python has several methods, which you will learn section-wise, such as bitwise operations, the sum() function, the half adder logic, and the fsum () function.
Method 1: Add Two Numbers Using Python Bitwise Operations
In bitwise operations, bits like 0 and 1 are involved, so using the bitwise operation, you can perform arithmetic operations like addition.
For example, look at the function below add_bitwise(), which adds two numbers.
def add_bitwise(a, b):
while b != 0:
carry = a & b # calculate the carry
a = a ^ b # sum of bits where at least one of the bits is not set
b = carry << 1 # carry is shifted by one so that adding it to 'a' gives the required sum
return a
print(add_bitwise(5, 3))You can see the output in the screenshot below.

From the output, you can see that when the numbers 5 and 3 are passed to the add_bitwise() function, the sum is 8.
Method 2: Add Two Numbers Using Sum() in Python
Python has a sum() function that takes an iterable of integers, such as a list, and returns the sum of those integers.
For example, you can add the same numbers 5 and 8 as in the above section using the sum() function.
# passing the 5 and 3 to sum() function to add the numbers
sum = sum([5,3])
print(sum)You can see the output in the screenshot below.

From the output, you can see that the two numbers are passed as a list [5, 3] to the sum() function to add them together; as a result, it returns the sum as 8.
Method 3: Add Two Numbers Using Half-Adder Logic
The half-adder logic is used in the combinational circuit, where two single-bit numbers are added to produce a sum or a carry. You can apply this logic to add two numbers in Python.
For example, let’s again add the two numbers using the half adder logic as shown below.
def half_adder(a, b):
while b != 0:
carry = a & b
a = a ^ b
b = carry << 1
return a
print(half_adder(5, 3))You can see the output in the screenshot below.

From the output, you can see that using the half-adder logic, two numbers, 5 and 3, are added together to produce a sum of 8.
Method 4: Add Two Numbers Using the fsum() Function
Python has a library called math which includes a function named fsum(), this fsum() function takes an iterable list a sum() function, but it takes elements as floating point.
Let’s use this function and see how to add two numbers.
import math
def add_using_fsum(a, b):
return math.fsum([a, b]) # using fsum() function to sum the float values
print(add_using_fsum(5, 3))You can see the output in the screenshot below.

From the output, you can see that two numbers, 5 and 3, are passed as an iterable like a list [5, 3] to the fsum() function, and as a result, it returns the sum as 8.0, which is correct but in float type.
So, that’s how you can add two numbers in Python without using arithmetic operators.
We explored multiple methods, bitwise, half-adder logic, sum(), and fsum() functions, and saw how each one works under the hood.
I personally prefer the bitwise method, as it’s the cleanest and most efficient. It also mirrors how real computers perform addition at the binary level.
You may like to read:
- Add Item to Set in Python
- Create an Empty Set in Python
- Compare Lists, Tuples, Sets, and Dictionaries in Python
- Python Set vs Tuple

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.