Articles

# Program to add two numbers using functions in Python

In this python programming article, we are going to learn

• program to add two numbers using function in python

### Program to find the sum of two numbers using functions in Python

The addition program in python using function to find the sum of two numbers is as follows:

``````# Owner : TutorialsInhand Author : Devjeet Roy

# Function Body
sum_of_numbers = n1 + n2
return sum_of_numbers

# Main Body
if __name__ == "__main__":
a = float(input("Enter first number: ")).strip()
b = float(input("Enter second number: ")).strip()

The output of the program to add two numbers using function in python is as follows:

``````PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter first number: 23
Enter second number: 12
The sum is 35.0``````

### Few important tips about the program

1. def keyword is used to define a function.

2. The variables n1 and n2 are called the parameters to a function.

3. The value which are passed to the parameters are known as arguments.

4. if __name__ == "__main__" is used to tell the python interpreter that our program starts from there. It is like the main() function in C or public static void main(String args[]) in Java.

Write a program to add two numbers using function in python.

This wraps up our session on python program to add two numbers using functions.

Python Numbers Program

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com