Python How To Add 2 Numbers Together: Easy Step By Step Guide

Logan Jul 13, 2026

Python is a powerful and versatile programming language, widely used in various fields such as data analysis, machine learning, web development, and scientific computing. One of the fundamental operations in any programming language is arithmetic, and Python facilitates this with its simple syntax and robust data types.

Simple Python Program to add Two number
Simple Python Program to add Two number

In this guide, we will explore how to add two numbers together in Python. Whether you're a beginner or an experienced programmer, understanding this basic operation is crucial to building more complex programs. So, let's dive right in!

Addition of 2 numbers in Python
Addition of 2 numbers in Python

Adding Numbers in Python

Python provides several ways to add numbers together. The most common method is using the plus operator (+). This operator can be used with both integers and floating-point numbers.

Sum of Two Numbers in Python or Adding Two Numbers
Sum of Two Numbers in Python or Adding Two Numbers

Here's a simple example demonstrating how to add two numbers using the plus operator:

```python # Example: Adding two integers num1 = 5 num2 = 3 result = num1 + num2 print(result) # Output: 8 ```

Integer Addition

All Important Python Functions for Beginners (Complete Cheat Sheet)
All Important Python Functions for Beginners (Complete Cheat Sheet)

In the example above, we're adding two integers (whole numbers). Python automatically performs integer addition when both operands are integers.

You can also perform binary addition using the plus operator. Binary numbers are represented in Python using the `0b` prefix:

```python # Example: Adding binary numbers binary_num1 = 0b101 binary_num2 = 0b110 result = binary_num1 + binary_num2 # Pythons automatic binary addition print(result) # Output: 1011 (decimal equivalent: 11) ```

Float Addition

PYTHON program to SWAP numbers
PYTHON program to SWAP numbers

Python also supports addition of floating-point numbers (numbers with decimal points). You can specify floating-point numbers in Python by appending a decimal point and the fractional part to an integer, like this: 3.14.

Here's an example of adding floating-point numbers in Python:

```python # Example: Adding floating-point numbers float_num1 = 2.5 float_num2 = 1.5 result = float_num1 + float_num2 print(result) # Output: 4.0 ```

Addition with User Input

a book cover with the title, 5 ways to draw numbers in python and other languages
a book cover with the title, 5 ways to draw numbers in python and other languages

In many Python programs, you'll want to add numbers provided by the user at runtime. Python provides the `input()` function to obtain user input from the standard input stream (usually the keyboard).

However, `input()` returns a string, so you'll need to convert it to a number (either `int` or `float`) using the `int()` or `float()` functions before performing addition. Here's an example:

an image of a computer screen with the text 2 without using a temporary variable
an image of a computer screen with the text 2 without using a temporary variable
a black background with text that reads swap two variable numbers in python, and the same number
a black background with text that reads swap two variable numbers in python, and the same number
a man holding up a poster with the words 5 levels of python on it
a man holding up a poster with the words 5 levels of python on it
Phyton
Phyton
Pi in Python — How It Works?
Pi in Python — How It Works?
the top 50 python project ideas
the top 50 python project ideas
📘 Python for Beginners Notes 🐍🔥
📘 Python for Beginners Notes 🐍🔥
"6 Python List Methods Every Beginner Should Know"
"6 Python List Methods Every Beginner Should Know"
Top 5 Python Projects for Beginners 🚀 (Start Coding Today)
Top 5 Python Projects for Beginners 🚀 (Start Coding Today)
Python Tip: Use zip() Like a Pro 🐍
Python Tip: Use zip() Like a Pro 🐍
5 Python Tricks That Will Save You Hours of Coding
5 Python Tricks That Will Save You Hours of Coding
Python list exercises guide
Python list exercises guide
Python Data Structures Cheat Sheet for Beginners (Lists, Tuples, Sets & Dictionaries)
Python Data Structures Cheat Sheet for Beginners (Lists, Tuples, Sets & Dictionaries)
How to Create A Bouncing Ball in Python?
How to Create A Bouncing Ball in Python?
an image of a computer screen with the text 4 using xor bitwise operation
an image of a computer screen with the text 4 using xor bitwise operation
Python Functions Cheat Sheet
Python Functions Cheat Sheet
python
python
5 Python Tricks You’ll Wish You Knew Sooner! 🐍✨
5 Python Tricks You’ll Wish You Knew Sooner! 🐍✨

```python # Example: Adding numbers provided by the user num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) result = num1 + num2 print(f"The sum of {num1} and {num2} is {result}") ```

Addition with Lists

In Python, the plus operator can also be used to add lists together. When adding lists, Python concatenates (appends) the elements of the second list to the end of the first list:

```python # Example: Adding lists list1 = [1, 2, 3] list2 = [4, 5, 6] result = list1 + list2 print(result) # Output: [1, 2, 3, 4, 5, 6] ```

It's important to note that adding lists with different data types will result in a `TypeError`. To avoid this, ensure that the lists you're adding together contain the same data types.

In addition to the plus operator, Python also provides functions in the `math` module for performing arithmetic operations, such as `add()`, which can be used to add numbers together. However, these functions are less commonly used than the plus operator.

That's it! You now know how to add numbers together in Python in various ways, from simple integers to user-provided input. Happy coding!