Add Two Numbers in Python



Adding two numbers in Python is one of the most basic tasks, where we need to combine their values to get a total.

In this article, we will see different ways to add two numbers in Python.

Using Arithmetic Operator

To add two numerical values in Python, we can use the addition operation, represented by the "+" symbol. It is one of the arithmetic operators in Python that performs the addition operation.

Example

Here is the basic example that adds the two numbers using the addition operator (+).

Open Compiler
# Assign values to the variables a = 7 b = 3 # Add two numbers using the addition operator result = a+b # Display the results print("Addition of two numbers: ") print(result)

On executing the above program, we will get the following output -

Addition of two numbers: 
10

Example

Following is another quick example that performs the addition operation on two numbers within the print() function.

Instead of storing the numbers and resultant value in the variables, this example directly adds the two numbers and prints the output in one statement using the Python print() function.

Open Compiler
print("Addition of two numbers:", 2+6)

Here is the output of the above program -

Addition of two numbers: 8

Using the Assignment Operator

In Python += symbol is called the augmented assignment operator, which performs both the addition and assignment operation in one statement.

Example

The following example adds the two numbers using the Python assignment operator(i.e., Augmented Addition Operator).

Open Compiler
# Assign values to the variables a = 7 b = 3 # Add two numbers using the assignment operator a += b print("Addition of two numbers: ") print(a)

On executing the above program, we will get the following output -

Addition of two numbers: 
10

Using the Built-in Function

In Python, sum() is a built-in function that can be used to add two numbers. This function generally takes numerical iterables to sum the values.

Example

In this example, we will give the list of two numbers to the sum() function to perform the addition of two numbers.

Open Compiler
# Assign values to the variables a = 7 b = 3 # Add two numbers using the sum() function result = sum([a, b]) print("Addition of two numbers: ") print(result)

On executing the above program, we will get the following output -

Addition of two numbers: 
10
Updated on: 2025-06-20T19:37:53+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements