Contents
Python Addition – Arithmetic Operator
Python Addition Operator takes two operands, one on the left and other on the right, and returns the sum of the these two operands.
The symbol used for Python Addition operator is +
.
Syntax
Following is the syntax of Python Addition Arithmetic Operator.
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
.
Example 1: Addition of 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)
Run Output
22
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)
Run Output
90
Example 2: 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)
Run Output
23.4
Example 3: 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)
Run 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.
Quiz - Let's see if you can answer these questions
Q1: Which of the following symbol is used for Python Arithmetic Addition?
Q3: How many operands does an Addition Operator take?
Q4: Which of the following datatypes are valid as operands for addition in Python?
Q5: Integer and Float can be added using + Operator in Python.
Q6: Which of the following statement throws TypeError?