Ekene Agunechemba

When you’re working with numbers in Python, you’ll often need to perform basic arithmetic operations. Python makes this super easy with built-in operators.


🧱 Basic Arithmetic Operators

Here are the main ones you need to know:

➕ Addition (+)

print(1 + 1)  # Output: 2

Explanation: Adds two numbers together.

➖ Subtraction (-)

print(2 - 1)  # Output: 1

Explanation: Subtracts the second number from the first.

✖️ Multiplication (*)

print(2 * 2)  # Output: 4

Explanation: Multiplies the numbers.

➗ Division (/)

print(4 / 2)  # Output: 2.0

Explanation: Divides the first number by the second and returns a float.

🧹 Modulus (%)

print(4 % 3)  # Output: 1

Explanation: Returns the remainder when dividing. 4 % 3 = 1.

🔼 Exponentiation (**)

print(4 ** 2)  # Output: 16

Explanation: Raises the first number to the power of the second. 4^2 = 16

🔻 Floor Division (//)

print(4 // 2)  # Output: 2

Explanation: Divides and rounds down (removes decimals).


🧪 Compound Assignment Operators

These are shortcuts for updating the value of a variable:

Let’s say:

age = 8

+=

age += 1  # Same as age = age + 1
print(age)  # Output: 9

-=

age -= 2
print(age)  # Output: 7

*=

age *= 2
print(age)  # Output: 14

/=

age /= 2
print(age)  # Output: 7.0

%=

age %= 5
print(age)  # Output: 2

You can also use **= and //= in the same way.


📓 Summary Table

Operator Meaning Example Result
+ Addition 2 + 3 5
- Subtraction 5 - 2 3
* Multiplication 3 * 3 9
/ Division 10 / 2 5.0
% Modulus 10 % 3 1
** Exponentiation 2 ** 3 8
// Floor Division 9 // 2 4

Now you’re ready to do some math with Python like a pro!

Review Questions

Here are 5 beginner-friendly practice questions to add at the end of your guide:


🧠 Practice Questions

  1. What will be the output?

    result = 10 % 4
    print(result)
    
  2. Which operator would you use to calculate 3 raised to the power of 4?

  3. Fill in the blank to increase the value of count by 5:

    count = 10  
    count ___ 5
    
  4. What will this code print?

    number = 20  
    number //= 3  
    print(number)
    
  5. Write a small code snippet that:

    • Starts with score = 5
    • Adds 2 to it
    • Multiplies the result by 3
    • Prints the final score

<
Previous Post
Javascript Regex: Validating User Input with Regular Expressions (RegEx) — A Nigerian Scenario 🇳🇬
>
Next Post
🔧 Create a Contact Form That Saves to Google Sheets and Sends Emails (With HTML, JS and Apps Script)