Add Two Numbers Using operator.add() Method
Initialize two variables num1, and num2. Find sum using the operator.add() by passing num1, and num2 as arguments and assign to su. Display num1,num2 and su
Python3
# Python3 program to add two numbers num1 = 15 num2 = 12 # Adding two nos import operator su = operator.add(num1,num2) # printing values print ( "Sum of {0} and {1} is {2}" . format (num1, num2, su)) |
Output
Sum of 15 and 12 is 27
Read More: Operator Functions
How to Add Two Numbers in Python – Easy Programs
Learn easy techniques and codes to add numbers in Python. Adding numbers in Python is a very easy task, and we have provided you 7 different ways to add numbers in Python.
Given two numbers num1 and num2. The task is to write a Python program to find the addition of these two numbers.
Examples:
Input: num1 = 5, num2 = 3
Output: 8
Input: num1 = 13, num2 = 6
Output: 19
There are many methods to add two number in Python:
- Using “+” operator
- Defining a function that adds two number
- Using operator.add method
- Using lambda function
- Using Recursive function
Each of these methods have been explained with their program below.