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
Following is the syntax of Python Addition Arithmetic Operator.
result = operand_1 + operand_2
operand_2 are numbers and the result is the sum of
Example 1: Addition of Numbers
In this example, we shall take two integers, add them, and print the result.
a = 10 b = 12 c = a + b print(c)
Chaining of Addition Operator
You can add more than two numbers in a single statement. This is because, Addition Operator supports chaining.
a = 10 b = 12 c = 5 d = 63 result = a + b + c + d print(result)
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.
a = 10.5 b = 12.9 result = a + b print(result)
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.
a = 1 + 8j b = 3 + 5j result = a + b print(result)
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?
Q2: What is the output of the following program?
a = 1 b = 2 c = 3 print( a + b + c )
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?