Lets Start Python Programming For Beginners to advanced. Operators in Python, Lectures 4.
[adrotate banner=”5″]
๐ Lecture 4: Operators in Python
๐ฏ Goal
By the end of this lecture, you will:
- Understand what operators are and how they work.
- Be able to use arithmetic , comparison , and logical operators.
- Write simple programs using math and logic.
- Build a mini calculator or number comparator.
๐ง What Are Operators?
Operators are symbols like +
, -
, *
, /
that help you do math or compare things.
They’re just like in math class โ but now you get to use them in code!
โ 1. Arithmetic Operators โ Doing Math
These are used for basic math operations.
Operator | Name | Example |
---|---|---|
+ | Addition | 5 + 3 โ8 |
- | Subtraction | 10 - 4 โ6 |
* | Multiplication | 3 * 5 โ15 |
/ | Division | 10 / 2 โ5.0 |
// | Floor Division | 7 // 2 โ3 |
% | Modulus (Remainder) | 10 % 3 โ1 |
** | Exponent | 2 ** 3 โ8 |
Example Code:
print(5 + 3)
print(10 / 2)
print(7 % 3)
๐ Output:
8
5.0
1
๐ง Kids Corner: Think of operators like buttons on a calculator โ each one does something special!

๐ข 2. Comparison Operators โ Comparing Values
These help you compare two values. They return either True
or False
.
Operator | Meaning | Example |
---|---|---|
== | Equal to | 5 == 5 โTrue |
!= | Not equal to | 5 != 3 โTrue |
> | Greater than | 7 > 5 โTrue |
< | Less than | 2 < 4 โTrue |
>= | Greater or equal | 5 >= 5 โTrue |
<= | Less or equal | 3 <= 2 โFalse |
Example:
age = 10
print(age > 5) # True
print(age == 10) # True
print(age < 8) # False
๐ค 3. Logical Operators โ Combining Conditions
Use these when you want to check more than one condition at once .
Operator | Use Case | Example |
---|---|---|
and | Both conditions must be true | (age > 5) and (age < 15) |
or | At least one is true | (color == "red") or (color == "blue") |
not | Reverses the result | not(age < 18) โ Is age NOT less than 18? |
Example:
age = 10
if (age > 5) and (age < 15):
print("You are between 6 and 14 years old.")
๐งช Try It Yourself!
Write a program that:
- Asks the user for two numbers.
- Adds, subtracts, multiplies, and divides them.
- Prints the results.
๐ก Sample Code:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print(f"Addition: {num1 + num2}")
print(f"Subtraction: {num1 - num2}")
print(f"Multiplication: {num1 * num2}")
print(f"Division: {num1 / num2}")
๐ฎ Mini Project: Simple Calculator
Letโs build a small calculator that tells the user if the first number is bigger than the second .
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
if num1 > num2:
print("The first number is bigger!")
else:
print("The second number is bigger or equal.")
๐ง Kids Corner
๐ง Imagine you have two toy boxes. You want to know:
- Are they the same size? (
==
) - Is one bigger than the other? (
>
) - Do I have more red toys OR blue toys? (
or
)
Thatโs exactly what weโre doing with operators โ comparing things!
[adrotate banner=”5″]
๐ Challenge (Optional)
Make a Magic Door Game where the player picks a door (1, 2, or 3), and you tell them what’s behind it using comparisons.
Example:
door = int(input("Choose a door (1, 2, or 3): "))
if door == 1:
print("A dragon appears!")
elif door == 2:
print("You find a treasure chest!")
elif door == 3:
print("Oops! A trap!")
else:
print("Invalid choice!")
๐ Summary
- Arithmetic operators help you do math (
+
,-
,*
,/
, etc.) - Comparison operators let you compare values (
==
,>
,<
, etc.) - Logical operators combine conditions (
and
,or
,not
) - These tools let you build calculators, games, and smart programs.
๐น Call Of Action
If this article was helpful to you, please Share and leave your feedback in the comment section below.
Python Programming For Beginners To Advanced
Python Programming For Beginners! Lecture 1
Python Programming! Variables and Data Types | Lectures 2
Python Programming! Input And Output | Lectures 3
Python Programming! Operators in Python Lectures 4
Python Programming! Conditional Statements Lectures 5