# How to add two numbers without using the “+” operator in Python 3.x. or earlier

Have you ever tried adding two numbers other than the conventional method? If not yet, then you must go through this blog so that you learn alternate ways to produce addition operation. ( Add two numbers without using “+” operator in Python )

## Add numbers without + operator in Python

In this tutorial, we will learn about adding two numbers without the use of the addition operator in Python 3.x. or earlier.

### Method 1: Using Arithmetic Operators(“-” & “*”)

Source Code:

```# program to add two numbers
# using arithmetic operations "-" & "*"

if a!=b:                   #when a is not equal to b
return (a*a-b*b)/(a-b)
else:
return 2*a      # we may also write 2*b

void main():
a=int(input())
b=int(input())

#main
main()

```

Description:     Here we used the mathematical identity a^2-b^2 = (a+b)(a-b).

When both the numbers are equal a-b will become zero and DivideByZero exception is raised. In order to avoid it, we have used else construct with the conditions 2*a or 2*b.

In case you are asked not to use the arithmetic operator. Then is there any alternative way out? My answer would be Yes. Now let’s take a look at how we can do it.

### Method 2: Without using Arithmetic Operators

```# Python Program to add two numbers
# without using arithmetic operators

# Iteration is continued till carry diminshes
while (b != 0):

# carry containing common set bits in a and b
carry = a & b # and operator

# Sum of bits of a and b only where at least one of the bits in them is not set
a = a ^ b   # xor operator

# Carry gets shifted by one so that after adding it to a gives the required sum
b = carry << 1

return a

void main():
a=int(input())
b=int(input())