Addition - Python Examples
Python Addition - Arithmetic Operator
Python Addition Operator is used to find the sum of given two numbers.
Addition Operator takes the two numbers as inputs, one on the left, and the other on the right, and returns the sum of the these two numbers.
The symbol used for Python Addition operator is +
.
Syntax
The syntax of Python Addition Arithmetic Operator with the inputs is given below.
result = operand_1 + operand_2
where operand_1
and operand_2
are numbers and the result is the sum of operand_1
and operand_2
.
1. Addition of two integer numbers
In this example, we shall take two integers, add them, and print the result.
Python Program
a = 10
b = 12
c = a + b
print(c)
Output
22
2. Chaining of Addition Operator
You can add more than two numbers in a single statement. This is because, Addition Operator supports chaining.
Python Program
a = 10
b = 12
c = 5
d = 63
result = a + b + c + d
print(result)
Output
90
3. Addition of Floating Point Numbers
Float is one of the numeric datatypes. You can compute the sum of floating point numbers using Python Addition operator. In the following example program, we shall initialize two floating point numbers, and find their sum.
Python Program
a = 10.5
b = 12.9
result = a + b
print(result)
Output
23.4
4. Addition of Complex Numbers
You can find the sum of complex numbers. In the following example program, we shall take two complex numbers and find their sum.
Python Program
a = 1 + 8j
b = 3 + 5j
result = a + b
print(result)
Output
(4+13j)
Summary
In this tutorial of Python Examples, we learned what Python Addition Arithmetic Operator is, how to use it to find the sum of two or more numbers.