Number Operations for Beginners

If Python could only store data and display it on the screen, programming wouldn’t be very engaging.

Fortunately, Python includes all the operators needed for arithmetic operations, and using them is similar to the mathematical notation we use daily. Python’s syntax is straightforward, so even if you’re new to programming, you’ll find this code easy to understand:

a = 10 + 5
b = a + 20
c = (a + b) * 2
print(a, b, c)

When you run this program, it will display:

15 35 100

In the first line, variable a gets the value from adding 10 and 5. The second line is more interesting — it adds the value of a (15) and 20, so b will be 35.

Operator precedence in Python matches regular mathematics, and you can change the execution order using parentheses. This is what happens in the third line.

The fourth line prints the values of all three variables.

In our guide, you’ll find a list of all arithmetic operators and operator precedence.