You have decided to explore the world of programming with Python. An essential part of any programming language are the mathematical operators that allow you to perform calculations of various kinds. In this guide, you will not only learn the basic mathematical operations but also experience the differences between Python 2 and Python 3. Let’s get started and take a look at the different types of calculations together.
Main insights
- In Python, you can perform basic mathematical operations such as addition, subtraction, multiplication, and division.
- Comments are a helpful way to make the code more understandable.
- The handling of integers and floating-point numbers differs between Python 2 and Python 3.
- Parentheses affect the order of calculations.
- You can calculate powers and roots.
- Variables allow complex calculations such as determining gross amounts including taxes.
Step-by-step guide
1. Basic operations in Python
Start by opening a Python environment, such as Jupyter Notebook. Here you can run your calculations directly.
The output should show you the result 7.
The result will be 2.

2. Multiplication and Division
For multiplication in Python, you use the asterisk (*).
The output is 25. If we want to perform the division, we do it with the slash (/)
In a Python 3 environment, you will get 1.5 here, while in Python 2, the result displayed will only be 1.

3. Difference between Python 2 and Python 3
One of the most important differences is that Python 2 returns only the integer part of the result when dividing two integers. If you want the exact result, you must ensure that you use at least one floating-point number.
In this case, you will get the result 1.5, regardless of whether you are using Python 2 or 3.

4. Considering the order of calculations
The use of parentheses is essential to influence the order of calculations.
This results in 110. This shows how important it is to use parentheses correctly.

5. Exponents and roots in Python
To calculate exponents, you use the double asterisk (**).
The result is 1024. For roots, you can use exponential notation, for example, by using 0.5.
This gives you the root of 4, which is 2.0.

6. Working with variables
With variables, you can perform more complex calculations. Let’s say you want to calculate the gross amount including VAT.
These calculations give you a complete overview of the amounts.

Summary – Mathematical operators in Python
With the mathematical operators in Python, you have a powerful foundation that offers you many possibilities for performing calculations. You have learned the basic operations, noticed the differences between Python 2 and Python 3, understood the importance of parentheses for the order of calculations, and utilized the concept of variables for extensive calculations.
Frequently Asked Questions
What are the basic operations in Python?The basic operations in Python are addition, subtraction, multiplication, and division.
How do Python 2 and Python 3 differ in division?Python 2 returns only the integer part, while Python 3 provides the exact result (floating-point).
Why are parentheses important in calculations?Parentheses influence the order of calculations and can therefore change the result.
How can I perform complex calculations with variables?Variables can be used to store values, which allows them to be used in mathematical expressions.
How can I calculate exponents and roots in Python?Exponents are calculated with '**', roots can be calculated using the exponential form with 0.5 for example.