LESSON – 2
PYTHON OPERATORS
Doing Math, Comparing Values, and Making Decisions
Topics Covered
• What are operators in Python?
• Arithmetic operators ( + , - , * , / , % , ** , // )
• Assignment operators ( = , += , -= , *= , /= and more )
• Relational / Comparison operators ( == , != , > , < , >= , <= )
• Logical operators ( and , or , not )
What You Will Learn Today
• You will understand what an operator is and why every program needs them.
• You will use all 7 arithmetic operators to do math like a Python pro.
• You will use shortcut assignment operators to update values in one line.
• You will compare values using relational operators and always get True or False as the
answer.
• You will combine conditions using and, or, and not to build smart decisions.
• You will reach your first MUSCLE MEMORY milestone: building rock-solid Python reflexes.
Learning Content
◆ What is an Operator?
An operator is a special symbol that tells Python to do something with values. You already
know operators from maths class — + adds numbers, − subtracts them. Python uses many of
these same symbols, plus a few new ones, to do four very different jobs.
EASY ANALOGY
Think of operators as the buttons on a calculator.
Different buttons do different jobs. The + button adds, the × button multiplies, the =
button stores your final answer.
Python’s operators work the same way — each symbol is a button that does one
specific thing. Today you learn all four families of buttons.
◆ Arithmetic Operators — The Math Family
Arithmetic operators do exactly what they say — they perform math. Python gives you 7 of
them. The first four (+, −, ×, ÷) you already know. The last three are new but easy.
Operator Name Example Result
+ Addition 5 + 3 8
- Subtraction 5 - 3 2
* Multiplication 5 * 3 15
/ Division 10 / 3 3.333...
Modulus
% 10 % 3 1
(leftover)
Exponent
** 2 ** 3 8
(power)
// Floor Division 10 // 3 3
Let’s see arithmetic operators at work. A shopkeeper is calculating a bill:
# A small shop bill
price = 200 # price of one notebook in Rs
qty = 3 # how many notebooks Arjun bought
total = price * qty # multiplication
print(total)
OUTPUT
600
Two arithmetic operators usually feel new to students: % (modulus) and // (floor division).
Let’s see them with a real example.
# Modulus % gives the LEFTOVER after dividing
chocolates = 10
friends = 3
leftover = chocolates % friends
print(leftover) # 10 split into 3 — each gets 3, 1 left over
# Floor division // gives the WHOLE-NUMBER part of a division
minutes = 145
hours = minutes // 60
print(hours) # 145 minutes = 2 full hours (25 mins left
over)
OUTPUT
1
2
EASY ANALOGY
Modulus % is the “leftover” operator.
Imagine you have 10 chocolates and want to share them equally with 3 friends.
Each friend gets 3 chocolates, and 1 chocolate is left in your hand.
That 1 is what % gives you — the leftover. Floor division // gives the opposite half
of the same story: how many full chocolates each friend got (3).
◆ Assignment Operators — The Storage Family
You already met the basic assignment operator in Session 1 — the equals sign =. It does not
mean ‘equals’ like in maths. It means ‘store this value in this box’.
Python gives you shortcut assignment operators that update a variable in one line, instead of
writing it the long way.
Operator Example Means the same as
= x = 10 Store 10 in x
+= x += 5 x = x + 5
-= x -= 3 x = x - 3
*= x *= 2 x = x * 2
/= x /= 4 x = x / 4
%= x %= 3 x = x % 3
**= x **= 2 x = x ** 2
//= x //= 2 x = x // 2
# Priya is collecting coins in a mobile game
coins = 100
coins += 50 # she earned 50 more -> coins is now 150
coins -= 20 # spent 20 on a power-up -> 130
coins *= 2 # got a double-coin bonus -> 260
print(coins)
OUTPUT
260
EASY ANALOGY
Assignment shortcuts are like saying “add 50 more coins to my piggy bank”.
Without the shortcut, you would have to say: take out all my current coins, add 50, then put them all ba
Python’s shortcut += does the same thing in one quick step.
◆ Relational Operators — The Comparison Family
Relational operators compare two values. The most important thing to remember: the answer
is ALWAYS True or False (a bool!). There are 6 of them.
Operator Meaning Example Result
== Equal to 5 == 5 True
!= Not equal to 5 != 3 True
> Greater than 7 > 3 True
< Less than 2 < 5 True
>= Greater than or equal 5 >= 5 True
<= Less than or equal 4 <= 4 True
WATCH OUT — = vs ==
= (one equals sign) means STORE — like putting a value into a box.
== (two equals signs) means COMPARE — asking ‘are these equal?’
Mixing these up is the most common beginner mistake. Read your code out loud: ‘store’ for = and ‘equa
# Comparing two friends' ages
my_age = 12
friend_age = 14
print(my_age == friend_age) # Are they the same age?
print(my_age < friend_age) # Am I younger?
print(my_age >= 12) # Am I at least 12?
OUTPUT
False
True
True
EASY ANALOGY
Relational operators are like a referee at a cricket match.
The referee looks at two scores and tells you “Team A is winning” (True) or “Team A is not winning” (Fal
The referee never says “maybe”. The answer is always one or the other — True or False — never anythin
◆ Logical Operators — The Decision Family
Logical operators work with True and False values. They let you combine multiple conditions
into one big decision. There are 3 of them: and, or, not.
Operator Meaning Example Result
and True only if BOTH sides are True True and False False
or True if AT LEAST ONE side is True True or False True
not Flips True to False and False to True not True False
# Should Karthik go play outside?
is_sunny = True
has_umbrella = False
# He can go if it is sunny AND he does not need an umbrella
print(is_sunny and not has_umbrella)
# He can also go if it is sunny OR he has an umbrella
print(is_sunny or has_umbrella)
OUTPUT
True
True
EASY ANALOGY
Think of and like your school: “You can play cricket IF homework is done AND it is not raining.” Both cond
Think of or like dessert at home: “You can have dessert IF you finished lunch OR you ate your vegetables
Think of not like a mirror that flips everything: not True becomes False, and not False becomes True.
MUSCLE MEMORY MILESTONE UNLOCKED!
You can now do math, update variables with shortcuts, compare values, and combine conditions in Pyth
These four operator families are the building blocks of every program you will ever write — from calcula
next YouTube video.
Practice these until they feel like reflexes. That is what ‘muscle memory’ means.
InClass Challenges
◆ InClass Challenge 1 — Rohan’s Cricket Score Card
Rohan just finished a friendly cricket match in his Mumbai colony. He scored 45 runs in the first
innings and 32 runs in the second. Before the match, he had set a personal target of 70 runs.
He wants Python to calculate his total runs, his average per innings, and whether he beat his
target.
Help Rohan by writing a Python program using arithmetic and relational operators.
Solution
# Rohan's Cricket Score Card
first_innings = 45
second_innings = 32
target = 70
# Arithmetic — total and average
total_runs = first_innings + second_innings
average = total_runs / 2
# Relational — did Rohan beat his target?
crossed_target = total_runs > target
print("Total runs:", total_runs)
print("Average per innings:", average)
print("Crossed target?", crossed_target)
OUTPUT
Total runs: 77
Average per innings: 38.5
Crossed target? True
◆ InClass Challenge 2 — Ananya’s Movie Night Eligibility Checker
Ananya is building a fun little ‘Movie Night Eligibility Checker’ for her family. The household
rules are:
• A person can watch a movie if they are at least 13 years old AND have finished their
homework.
• If it is a weekend, the homework rule does not matter — they can still watch.
Help Ananya write a program using relational and logical operators that decides whether the
family member can watch.
Solution
# Ananya's Movie Night Checker
age = 14
homework_done = False
is_weekend = True
# Rule 1 — at least 13 AND homework done
rule_1 = age >= 13 and homework_done
# Rule 2 — it is the weekend (homework doesn't matter)
rule_2 = is_weekend
# Can watch if EITHER rule is satisfied
can_watch_movie = rule_1 or rule_2
print("Age check passed?", age >= 13)
print("Rule 1 (age + homework):", rule_1)
print("Rule 2 (weekend bonus):", rule_2)
print("Can watch movie?", can_watch_movie)
OUTPUT
Age check passed? True
Rule 1 (age + homework): False
Rule 2 (weekend bonus): True
Can watch movie? True
Home Tasks
◆ Home Task 1 — Dev’s Pocket Money Tracker
Dev got Rs 500 as his weekly pocket money. During the week he spent Rs 120 on snacks at the
school canteen, Rs 75 on a new comic book, and his elder sister gave him an extra Rs 200 for
helping clean her room.
Write a Python program for Dev using assignment shortcut operators (+= and -=) to update
his money step by step, then print the final balance.
Solution
# Dev's Pocket Money Tracker
pocket_money = 500 # start of the week
pocket_money -= 120 # snacks at canteen
pocket_money -= 75 # comic book
pocket_money += 200 # bonus from sister
print("Dev's final pocket money: Rs", pocket_money)
OUTPUT
Dev's final pocket money: Rs 505
◆ Home Task 2 — Sneha’s Basketball Team Eligibility
Sneha wants to join her school’s basketball team. The coach has set these conditions:
• Main rule: You must be taller than 150 cm AND faster than 8 seconds in the 50 -metre
dash.
• Bonus rule: If you have played basketball for more than 2 years AND are taller than 150
cm, you can join even without meeting the speed rule.
Sneha is 152 cm tall, runs the 50-metre dash in 8.5 seconds, and has been playing basketball
for 3 years. Write a Python program that uses arithmetic, relational, AND logical operators to
decide whether she qualifies.
Solution
# Sneha's Basketball Team Eligibility Checker
height_cm = 152
sprint_time = 8.5 # in seconds
years_playing = 3
# Main rule — tall AND fast
main_rule = height_cm > 150 and sprint_time < 8
# Bonus rule — tall AND experienced
bonus_rule = height_cm > 150 and years_playing > 2
# Qualify if EITHER rule passes
can_join_team = main_rule or bonus_rule
print("Height OK?", height_cm > 150)
print("Speed OK?", sprint_time < 8)
print("Experienced?", years_playing > 2)
print("Main rule passed?", main_rule)
print("Bonus rule passed?", bonus_rule)
print("Can Sneha join the team?", can_join_team)
OUTPUT
Height OK? True
Speed OK? False
Experienced? True
Main rule passed? False
Bonus rule passed? True
Can Sneha join the team? True
WHAT COMES NEXT?
STRINGS + AI TEXT MAGIC
— End of Lesson – 2 —