Hey guys, welcome back!
If you’re new here, welcome to this Python learning series.
In the last few posts, we’ve explored variables, constants, and how Python reads your instructions line by line. But today, we’re going to dive into something that you’ll use all the time — numeric expressions.
Now, don’t worry — this isn’t your high school algebra class. Python math is way more chill and once you understand it, it’ll feel completely natural to use.
What Are Numeric Expressions?
A numeric expression is simply a math operation — like addition, subtraction, multiplication, or division — that uses numbers, variables, and arithmetic operators in Python.
The most common symbols (operators) used are:
-
+for addition -
-for subtraction -
*for multiplication -
/for division
In addition to these, there are two more important operators:
-
**for exponent (power) -
%for modulus (remainder)
We’ll go through all of them with examples.
Simple Addition Example
Let’s start with a basic one:
result = 10 + 5
print(result)
Output:
15
Here, Python just adds 10 and 5 and gives you the result. Nothing fancy — just clean and simple addition.
Expressions with Multiple Operators
Now let’s try something slightly more interesting:
result = (3 + 7) * 2
print(result)
Output:
20
Let’s break it down:
-
Normally, Python would multiply first and then add.
-
But since we used parentheses
(3 + 7), Python adds those first to get10, and then multiplies by2to get20.
So, always remember: whatever is inside the parentheses gets done first — just like in normal math.
🔤 Using Variables in Expressions
You can also use variables inside your expressions.
Example:
x = 5
y = 3
result = x + y * 2
print(result)
Output:
11
Here’s what’s happening:
-
Python multiplies
y * 2first (since multiplication has higher priority). -
Then it adds
x. -
So,
3 * 2 = 6and5 + 6 = 11.
If you want to add first and then multiply, use parentheses:
result = (x + y) * 2
print(result)
Output:
16
Parentheses change the order of operations, so Python adds first, then multiplies.
Division in Python
Let’s look at division:
result = 10 / 2
print(result)
Output:
5.0
Even though 10 / 2 equals 5, Python gives you 5.0 — a float value.
That’s because division in Python always returns a float, even if the result is a whole number.
Exponent (Power) Operator
If you remember math notation like 2² or 2³ — that’s what we call power or exponentiation.
In Python, we use ** for that.
Example:
result = 2 ** 3
print(result)
Output:
8
That’s because 2³ = 2 × 2 × 2 = 8.
This is super helpful when you’re working with formulas, interest rates, or even game logic.
Modulus (Remainder) Operator
The modulus operator % gives you the remainder after division.
Example:
print(7 % 2)
Output:
1
Let’s understand this with a fun example:
Imagine you have 7 chocolates and you want to share them equally between 2 people.
-
Each person gets 3 chocolates.
-
You’ll have 1 chocolate left.
That leftover chocolate — the remainder — is what Python gives you with %.
Another example:
print(10 % 2)
Output:
0
Because 10 divides evenly by 2, there’s no remainder.
🧠 Quick Recap
Let’s quickly summarize what we learned today about numeric expressions in Python:
| Operator | Meaning | Example | Output |
|---|---|---|---|
+ |
Addition | 10 + 5 |
15 |
- |
Subtraction | 10 - 5 |
5 |
* |
Multiplication | 3 * 4 |
12 |
/ |
Division | 10 / 2 |
5.0 |
** |
Exponent | 2 ** 3 |
8 |
% |
Modulus (Remainder) | 7 % 2 |
1 |
🎮 Practice Time!
You’ll use these numeric expressions everywhere — whether you’re building a calculator, game, or working with numbers in data.
Play around with different combinations.
Try swapping parentheses, changing numbers, and seeing how the results change.
That’s the best way to make it stick!
In the next part, we’ll explore inputs and outputs in Python — an essential step in making your programs more interactive.
Thanks for reading, and as always —
Keep learning Python and happy coding! 💻
Copyright statement: Unless otherwise indicated, all articles are original to this site, please cite the source when sharing.
Article link:http://pybeginners.com/simplified-python/numeric-expressions-in-python-simplified-for-beginners/
License agreement:Creative Commons Attribution-NonCommercial 4.0 International License