# Python program to add two numbers

In this post, you will learn different ways to write **Python programs** to add two numbers.

The addition of numbers is the most basic operation that is applicable in most of the programs. Such type of programming can improve your logical skills and make us perfect for coding challenges. There are many approaches in Python to perform addition operation.

## Python Adding two numbers using + operator

In the given program, we have used the (+) operator to add two numbers -

```
# Python program to add two numbers
num1 = 1200
num2 = 232
# Using + operator to add two numbers
sum = num1 + num2
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
```

**Output of the above code -**

`The sum of 1200 and 232 is 1432`

## Adding two user inputs

In the given program, the user is first asked to enter two numbers. We have stored the numbers in two variables and added them using the arithmetic plus (+) operator, and the result is stored in the variable sum. As the **input()** function returns a string, so we need to convert the string into a number using the **float()** function.

```
# Python program to add two numbers
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# adding two numbers
sum = num1+ num2
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
```

**Output of the above code -**

```
Enter the first number: 212
Enter the second number: 42312
The sum of 212.0 and 42312.0 is 42524.0
```

## Python single statement to add two numbers

In the above programs, we have used multiple lines of codes to get the sum of two numbers. But, we can perform this operation in just a single statement without using any variable as follows -

`print('The sum is %.1f' %(float(input('Enter first number: '))+float(input('Enter second number: '))))`

**Output of the above code -**

```
Enter first number: 210
Enter second number: 3
The sum is 213.0
```

### Related Articles

**
Python program to print multiplication table from 1 to 10
Multiply all elements in list Python
Python Check if a Number is Odd or EvenPython program to multiply two numbers numpy dot product Prime factors of a number in Python Find square of a number in Python How to find average of n numbers in Python Python program for Prime Number Power of a number using recursion in Python Sum of n numbers in python using for loop Sum of n numbers in Python using while loop Swapping of two numbers in Python Python iterate list with index Python add list to list Python random choice Python check Palindrome strings and numbers Remove character from string Python Python raise keyword**