Sibling War Made Python Operators Easy!

Table of contents
- Let The War Begin
- 1. Arithmetic Operators — The Beginning of the Snack Battle
- 2. Comparison Operators — Who Has More?
- 3. Assignment Operators — Quick Adjustments
- 4. Logical Operators — Fight Conditions
- 5. Bitwise Operators — Dad's Secret Tech Trick
- 6. Identity Operators — Same Snacks or Different?
- 7. Membership Operators — Snacks in Box?
- Summary
We often think learning programming is tough, full of complex code and dry examples. But what if I told you that even your daily family drama can teach you Python?
Let me introduce you to Tinku and Chinku, two naughty brothers who turned their fight for snacks into a real-life Python lesson on Operators.
Let The War Begin
Tinku and Chinku — the legendary snack fighters — were at it again. Chocolates and toffees were flying everywhere, and their complaints were louder than a school bell! But their mom, the ultimate problem solver, stepped in.
Little did they know… their silly fight was about to teach them — and us — a real-life lesson in Python Arithmetic Operators!
1. Arithmetic Operators — The Beginning of the Snack Battle
Arithmetic operators are used to perform basic mathematical operations like addition (
+
), subtraction (-
), multiplication (*
), division (/
), floor division (//
), modulus (%
), and exponentiation (**
).
The war had officially begun…
Tinku , always quick on his feet, quietly grabbed 3 chocolates and 7 toffees.
Chinku, never one to fall behind, managed to snatch 5 chocolates and 3 toffees for himself.
Soon, their house turned into a mini battlefield of snacks flying everywhere! But as always, their mom came in to restore peace — with maths.
Operator | Symbol | Meaning |
Addition | + | Adds two numbers |
Subtraction | - | Subtracts one number from another |
Multiplication | * | Multiplies two numbers |
Division | / | Divides and returns float result |
Floor Division | // | Divides and returns whole part only |
Modulus | % | Returns remainder of division |
Exponentiation | ** | Raises first number to power of second |
Addition (+
) — Mom adds total chocolates
She adds:
Tinku’s Chocolates
3
+ Chinku’s Chocolates5
→ Total8
Tinku’s Toffees
7
+ Chinku’s Toffees3
→ Total10
Mom smiles, "8 chocolates, 10 toffees…
tinku_chocolates = 3
tinku_toffees = 7
chinku_chocolates = 5
chinku_toffees = 3
total_chocolates = tinku_chocolates + chinku_chocolates
total_toffees = tinku_toffees + chinku_toffees
print(total_chocolates, total_toffees)
8, 10
Subtraction (-
) — Tinku eats secretly
Tinku secretly ate 2 chocolates and 4 toffees, but mom noticed:
tinku_ate_chocolates = 2
tinku_ate_toffees = 4
Remaining_chocolates = total_chocolates - tinku_ate_chocolates
Remaining_toffees = total_toffees - tinku_ate_toffees
print(Remaining_chocolates, Remaining_toffees)
6, 6
Multiplication (*
) — Papa doubles snacks
The chaos got so loud that their dad couldn’t handle it anymore. Dad declared, “Enough! Let me double everything, so no one fights!”
final_total_chocolates = Remaining_chocolates * 2
final_total_toffees = Remaining_toffees * 2
print(final_total_chocolates, final_total_toffees)
12, 12
Division (/
) — Fair Sharing Between Brothers
With so many snacks, Chinku demanded, “We share everything equally, or this war isn’t over!”
chocolates_per_child = final_total_chocolates / 2
toffees_per_child = final_total_toffees / 2
print(chocolates_per_child, toffees_per_child)
6.0, 6.0
Floor Division (//
) — Whole snacks only
Just when Tinku and Chinku thought their fight was under control, their elder sister stepped in — with her own evil plan!
She quietly added 3 extra chocolates and 3 toffees, just to spice things up and enjoy the drama.
But their mom, always alert, wanted to divide the snacks fairly — but only whole snacks count, no half chocolates allowed! That’s where Floor Division (//
) comes in.
final_total_chocolates += 3 # Now 15
final_total_toffees += 3 # Now 15
chocolates_per_child = final_total_chocolates // 2
toffees_per_child = final_total_toffees // 2
print(chocolates_per_child, toffees_per_child)
7, 7
Using //
Floor Division:
Only whole snacks are divided — fractions ignored.
So, each child gets 7 chocolates, 7 toffees, and the leftover? Well… the fight for that leftover starts again!
Modulus (%
) — Leftover count
Tinku and Chinku's elder sister succeeded — the fight wasn’t over yet!
After fair sharing, 1 chocolate and 1 toffee were still leftover — the reason? That sneaky remainder!
Mom used the Modulus Operator %
to calculate exactly how many snacks were leftover after the division.
leftover_chocolates = final_total_chocolates % 2
leftover_toffees = final_total_toffees % 2
print(leftover_chocolates, leftover_toffees)
1, 1
Exponentiation (**
) — Snack Magic
After the snack war, here’s where things stood:
1 leftover chocolate
1 leftover toffee
Both lying on the table, both brothers eyeing them like lions ready to pounce.
Now, Father stepped in, picked up both leftover snacks together and smiled,
"Instead of fighting, let's apply some exponential magic — Python style!"
total_items = leftover_chocolates + leftover_toffees # 2
power = 3
final_items = total_items ** power
print(final_items)
8
No more fighting, just a pile of delicious snacks ready to be shared.
Now, I think you’re getting familiar with the Python syntax — variables, operators, print statements — so let’s deep dive into the other operators a little faster, but with the same fun, real-life sibling drama!
2. Comparison Operators — Who Has More?
These operators compare two values and return either
True
orFalse
based on the condition. Examples include greater than (>
), less than (<
), equal to (==
), etc.
In every sibling fight, the most common thing is comparison —
"Who has more chocolates?"
"Who got extra toffees?"
In Python, just like in real life, Comparison Operators help us compare two things and decide the truth.
Comparison Operators compare values and return either True or False based on the condition:
Operator | Meaning | Example |
> | Greater Than | 5 > 3 → True |
< | Less Than | 2 < 5 → True |
== | Equal To | 4 == 4 → True |
!= | Not Equal To | 3 != 2 → True |
>= | Greater Than or Equal To | 5 >= 5 → True |
<= | Less Than or Equal To | 3 <= 4 → True |
tinku_chocolates = 7
chinku_chocolates = 7
print(tinku_chocolates > chinku_chocolates) # False
print(tinku_chocolates == chinku_chocolates) # True
False
True
3. Assignment Operators — Quick Adjustments
Assignment operators are used to assign values to variables or update existing values quickly, such as
=
,+=
,-=
,*=
,/=
, etc.
Operator | Example | Meaning |
= | x = 5 | Assign value to variable |
+= | x += 2 | Add & update (x = x + 2 ) |
-= | x -= 1 | Subtract & update |
*= | x *= 3 | Multiply & update |
/= | x /= 2 | Divide & update |
total_chocolates = 10
total_chocolates += 5 # Mom adds 5 chocolates
total_chocolates -= 2 # Chinku eats 2 chocolates
print(f"Chocolates left: {total_chocolates}")
Chocolates left: 13
4. Logical Operators — Fight Conditions
Logical operators help combine multiple conditions and return
True
orFalse
based on logical relations like AND, OR, NOT.
Operator | Meaning | Example |
and | Both conditions true | True and False → False |
or | At least one true | True or False → True |
not | Reverse the truth | not True → False |
enough_snacks = True
fight_stopped = False
# Logical AND
print(enough_snacks and fight_stopped) # False
# Logical OR
print(enough_snacks or fight_stopped) # True
# Logical NOT
print(not enough_snacks) # False
False
True
False
5. Bitwise Operators — Dad's Secret Tech Trick
Bitwise operators perform operations on binary bits of numbers — works at a low level, perfect for hidden calculations.
Operator | Example | Meaning |
& | x & y | Bitwise AND |
` | ` | `x |
^ | x ^ y | Bitwise XOR |
~ | ~x | Bitwise NOT |
x = 3 # Binary: 011
y = 2 # Binary: 010
print(x & y) # AND → 010 → 2
print(x | y) # OR → 011 → 3
print(x ^ y) # XOR → 001 → 1
print(~x) # NOT → Inverts bits
2
3
1
-4
6. Identity Operators — Same Snacks or Different?
Identity operators check whether two variables refer to the same memory location, not just same value.
Operator | Meaning | Example |
is | Same object | snack1 is snack3 → True |
is not | Different object | snack1 is not snack2 → True |
snack1 = [1, 2, 3]
snack2 = [1, 2, 3]
snack3 = snack1
print(snack1 is snack3) # True — Same object
print(snack1 is snack2) # False — Different objects
True
False
7. Membership Operators — Snacks in Box?
Membership operators check if an element exists within a sequence like a list, string, or set.
Operator | Meaning | Example |
in | Present | "chocolate" in box |
not in | Not present | "juice" not in box |
snack_box = ["chocolate", "toffee", "biscuit"]
print("chocolate" in snack_box) # True
print("juice" not in snack_box) # True
True
True
Summary
Operator Type | Symbol/Example | Meaning/Use |
Arithmetic | + , - , * , / , // , % , ** | Perform basic math operations like add, subtract, multiply, divide, floor divide, modulus, exponentiation. |
Assignment | = , += , -= , *= , /= , etc. | Assign or update values of variables quickly. |
Comparison | > , < , == , != , >= , <= | Compare two values, returns True or False . |
Logical | and , or , not | Combine multiple conditions logically. |
Bitwise | & , ` | , ^, ~, <<, >>` |
Identity | is , is not | Check if two variables are the same object in memory. |
Membership | in , not in | Check if a value exists within a sequence. |
"And that’s how a simple snack fight turned into the sweetest Python lesson ever! Next time you grab a chocolate, remember — even snacks follow Python rules."
Subscribe to my newsletter
Read articles from Nitish kalyan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
