Skip to content

Python Programming! Operators in Python Lectures 4

A cartoon math lab where a robot and a child are solving problems together

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.

OperatorNameExample
+Addition5 + 3โ†’8
-Subtraction10 - 4โ†’6
*Multiplication3 * 5โ†’15
/Division10 / 2โ†’5.0
//Floor Division7 // 2โ†’3
%Modulus (Remainder)10 % 3โ†’1
**Exponent2 ** 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!

A cartoon math lab where a robot and a child are solving problems together
A cartoon math lab where a robot and a child are solving problems together

๐Ÿ”ข 2. Comparison Operators โ€“ Comparing Values

These help you compare two values. They return either True or False.

OperatorMeaningExample
==Equal to5 == 5โ†’True
!=Not equal to5 != 3โ†’True
>Greater than7 > 5โ†’True
<Less than2 < 4โ†’True
>=Greater or equal5 >= 5โ†’True
<=Less or equal3 <= 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 .

OperatorUse CaseExample
andBoth conditions must be true(age > 5) and (age < 15)
orAt least one is true(color == "red") or (color == "blue")
notReverses the resultnot(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:

  1. Asks the user for two numbers.
  2. Adds, subtracts, multiplies, and divides them.
  3. 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

Najeeb Alam

Najeeb Alam

Technical writer specializes in developer, Blogging and Online Journalism. I have been working in this field for the last 20 years.

Leave a Reply

Your email address will not be published. Required fields are marked *