Add Two Numbers in Python Using Function
This program show adding two numbers in Python using function. We can define a function that accepts two integers and returns their sum.
Python3
#To define a function that take two integers # and return the sum of those two numbers def add(a,b): return a + b #initializing the variables num1 = 10 num2 = 5 #function calling and store the result into sum_of_twonumbers sum_of_twonumbers = add(num1,num2) #To print the result print ( "Sum of {0} and {1} is {2};" . format (num1, num2, sum_of_twonumbers)) |
Output
Sum of 10 and 5 is 15;
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.
Contact Us