Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Arithmetic operators are used to perform mathematical calculations in Python.
You already use these calculations in everyday life:
Python can do all of these calculations for you.
For example:
The result is:
Python provides several arithmetic operators:
| Operator | Name | Example | Result |
|---|---|---|---|
+ | Addition | 10 + 5 | 15 |
- | Subtraction | 10 - 5 | 5 |
* | Multiplication | 10 * 5 | 50 |
/ | Division | 10 / 5 | 2.0 |
% | Modulus | 10 % 3 | 1 |
** | Exponentiation | 2 ** 3 | 8 |
// | Floor Division | 10 // 3 | 3 |
Don't worry if some of these look new.
We will understand each one with simple examples.
+)The + operator is used to add two numbers.
Output:
Another example:
Output:
Suppose you have:
Python can calculate:
Output:
+ means add.-)The - operator is used to subtract one number from another.
Output:
Another example:
Output:
Suppose you have ₹1,000 and spend ₹250.
Output:
- means subtract.*)The * operator is used to multiply numbers.
In Python, multiplication uses an asterisk *.
Output:
Another example:
Output:
Suppose one notebook costs ₹50 and you buy 4 notebooks.
Output:
* means multiply./)The / operator is used to divide one number by another.
Output:
Notice that Python gives:
instead of:
The / operator produces a division result in decimal form.
Another example:
Output:
Output will be approximately:
/ means division.%)The % operator is called the modulus operator.
It gives us the remainder after division.
This is one of the most useful arithmetic operators.
Let's understand it:
So:
Output:
Output:
Why?
Because 20 can be divided by 5 exactly.
Think:
% asks: "What is left after division?"For example:
Output:
Because:
% gives the remainder.**)The ** operator is used to calculate powers.
For example:
This means:
So the result is:
Another example:
This means:
Output:
** means power or exponentiation.//)The // operator performs division and returns the whole-number part of the result by rounding down.
Normal division:
Floor division:
So:
Output:
Another example:
Output:
Because:
and floor division gives:
/ gives the normal division result.
// gives the result rounded down to the nearest whole number.Here is an easy way to remember all arithmetic operators:
| Operator | What it does | Example | Result |
|---|---|---|---|
+ | Adds numbers | 8 + 2 | 10 |
- | Subtracts numbers | 8 - 2 | 6 |
* | Multiplies numbers | 8 * 2 | 16 |
/ | Divides numbers | 8 / 2 | 4.0 |
% | Gives remainder | 8 % 3 | 2 |
** | Calculates power | 2 ** 3 | 8 |
// | Floor division | 8 // 3 | 2 |
Python can use more than one arithmetic operator in a single calculation.
For example:
The result is:
Why is the answer 20 and not 30?
Because Python follows a specific order of operations.
When multiple arithmetic operators are used together, Python follows a mathematical order.
A simple rule to remember is:
Click to ZoomYou can remember the basic idea as:
Python first performs:
Then:
So the output is:
This time, the parentheses are calculated first:
Then:
Output:
Notice how parentheses changed the result.
().Now it's your turn.
Try to predict the output before running each program.
Expected Output:
Expected Output:
Expected Output:
Expected Output:
Expected Output:
Expected Output:
Expected Output:
Try to calculate the answer before running the code:
Think carefully about the order of operations.
Try these calculations yourself.
Before running the code, write down what you think the output of each line will be.
Then run the program and check your answers.
x instead of *In normal mathematics, multiplication is sometimes written using ×.
In Python, multiplication uses:
Correct:
Not:
/ and //Remember:
gives approximately:
while:
gives:
% with PercentageIn Python, % is the modulus operator.
It gives the remainder after division.
For example:
Output:
Look at:
Python performs multiplication first:
So the result is:
Use parentheses when you want a different order:
Output:
Arithmetic operators help Python perform mathematical calculations.
The main arithmetic operators are:
+ → Addition- → Subtraction* → Multiplication/ → Division% → Remainder** → Power// → Floor DivisionPython can also combine multiple operators in one calculation.
When calculations are combined, Python follows an order of operations.
% return?** do?You now know how Python performs basic mathematical calculations using arithmetic operators.
Practice these operators by writing your own calculations and predicting the output before running the code.
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| String Methods | Assignment Operators |
Test your understanding of this lesson with 8 questions. Each question has one correct answer.