Day 4: Python Operators Made Easy – Arithmetic, Logical & Comparison Explained

Welcome to Day 4 of our Learn Python in 30 Days challenge! Todayโ€™s focus is Python operators for beginners โ€” the tools that allow Python to perform calculations, comparisons, and logical decisions.

๐Ÿ“Œ Missed earlier parts? Catch up here:

โž• 1. Arithmetic Operators in Python

Arithmetic operators in Python help you perform basic mathematical operations, just like a calculator – but inside your code. Whether you want to add marks, calculate averages, or divide money equally among friends, these operators make it easy.

Here are the most common ones:

OperatorFunctionExample
+Addition4 + 2 = 6
Subtraction5 – 3 = 2
*Multiplication3 * 2 = 6
/Division10 / 2 = 5.0
//Floor Division10 // 3 = 3
%Modulus10 % 3 = 1
**Exponent (Power)2 ** 3 = 8
math_score = 90
science_score = 85
total= math_score + science_score
average= total / 2
print("Total marks:", total)
print("Average marks:, average)
Output

Total marks: 175
Average marks: 87.5

These are the operators that form the foundation of any programming logic – whether it’s building a calculator, budgeting app, or even a game.

๐Ÿ“ 2. Assignment Operators โ€“ Storing and Updating Values

Assignment operators help Python remember values by storing them in Variables. Think of them as the “equal to” button on a calculator – but more powerful. You can also update a variable using shorthand.

OperatorsMeaningExampleSame As
=Assign valuex = 10
+=Add & assignx += 5x = x + 5
-=Subtract & assignx -= 3x = x – 3
*=Multiply & assignx *= 2x = x * 2
/=Divide & assignX /= 4x = x / 4
coins = 10
coins += 5  #You found 5 more coins
coins -= 2.  #You spent 2 coins
print("Remaining coins:", coins)
Output

Remaining coins: 13

Assignment operators are a clean and efficient way to update variables without repeating yourself.

โ“ 3. Comparison Operators โ€“ Asking Python to Compare Things

Comparison operators help you ask questions in your code like:

  • “Is this number bigger than that one?”
  • “Are these two values equal?”

They’re used in if statements and conditions – where Python needs to decide what to do.

OperatorMeaningExample
==Equal to4 == 4 โ†’ True
!=Not equal to4 != 5 โ†’ True
>Greater than7 > 5 โ†’ True
<Less than2 < 6 โ†’ True
>=Greater or equal5 >= 5 โ†’ True
<=Less or equal3 <= 2 โ†’ False
age = 16
if age >= 18:
    print("You can vote!")
else:
    print("You are too young to vote.")
Output 

You are too young to vote.

These operators help Python make decisions and are used heavily in real-world program like login systems, exam results, checks, and games.

๐Ÿ”— You May Also Like:

๐Ÿง  4. Logical Operators โ€“ Making Smart Decisions

Logical operators in Python help your program make multiple decisions at once. Instead of checking one condition, you can check two or more together.

They answer questions like:

  • “Are both conditions true?”
  • “Is at least on condition true?”
  • “Is this condition not true?”

Python has 3 logical operators: and, or, not

OperatorDescription
andReturns True if both conditions are True
orReturns True if at least one condition is True
notReverses the result

1 Both conditions must be true

age = 18
citizen = True
if age >= 18 and citizen:
    print("You can vote.")
else:
    print("You can not vote.")

Output: You can vote.

Used when both conditions must be true

2 At least one condition must be true

has_id = False
has_passport = True

if has_id or has_passport:
     print("You can enter the exam hall.")
else:
     print("Access denied.")

Output: You can enter the exam hall.

Used when any one of the conditions being true is enough.

3. Reverse the result

is_raining = False

if not is_raining:
    print("Let's go outside!")
else:
    print("Stay indoors.")

Output: Let’s go outside!

Used when you want to check if something is not true.

Real-Life Example (All 3 Together):

username = "admin"
password = "1234"
logged_in = True

if username == "admin" and password == "1234" and logged_in:
       print("Welcome to your dashboard!")
else:
       print("Access denied.")
        

Logical operators make your code smarter and are heavily used in:

  • Login systems
  • Games
  • Form validations
  • Conditional calculations

๐Ÿ“˜ Recap: What You Learned in Day 4

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators

๐Ÿ”ฎ Whatโ€™s Next?

In Day 5, weโ€™ll cover if, else, and elif statements โ€” how Python makes decisions.

๐Ÿ’ฌ Your Turn!

  • Comment below: Whatโ€™s your favorite operator so far
  • Share this post if it helped you understand Python better.

Leave a Comment