Learning Objectives
After completing this lesson, students will be able to:
- Define an operator.
- Understand the purpose of operators.
- Identify different types of Python operators.
- Use arithmetic, comparison, logical, assignment and membership operators.
- Write simple Python programs using operators.
Prerequisite Knowledge
- Basic Python syntax.
- Variables.
- Data types (int, float, str).
- Using the
print() function.
What is an Operator?
An operator is a special symbol that performs an operation on one or more values (called operands).
Example:
x = 10
y = 5
print(x + y)
Output:
15
Here,
+ is the operator.
Types of Operators in Python
| Operator Type |
Purpose |
| Arithmetic Operators |
Perform mathematical calculations. |
| Comparison Operators |
Compare two values. |
| Logical Operators |
Combine logical conditions. |
| Assignment Operators |
Assign values to variables. |
| Membership Operators |
Check whether a value exists in a sequence. |
1. Arithmetic Operators
| Operator |
Meaning |
Example |
| + |
Addition |
10 + 5 = 15 |
| - |
Subtraction |
10 - 5 = 5 |
| * |
Multiplication |
10 * 5 = 50 |
| / |
Division |
10 / 5 = 2.0 |
| // |
Floor Division |
11 // 2 = 5 |
| % |
Modulus (Remainder) |
11 % 2 = 1 |
| ** |
Exponent |
2 ** 3 = 8 |
a = 12
b = 5
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a//b)
print(a%b)
print(a**2)
2. Comparison Operators
| Operator |
Meaning |
Example |
| == |
Equal To |
5 == 5 → True |
| != |
Not Equal To |
5 != 4 → True |
| > |
Greater Than |
8 > 4 → True |
| < |
Less Than |
3 < 5 → True |
| >= |
Greater Than or Equal To |
7 >= 7 → True |
| <= |
Less Than or Equal To |
5 <= 8 → True |
3. Logical Operators
| Operator |
Description |
Example |
| and |
Returns True if both conditions are True. |
5>2 and 8>3 |
| or |
Returns True if at least one condition is True. |
5<2 or 8>3 |
| not |
Reverses the result. |
not(5>2) |
4. Assignment Operators
| Operator |
Example |
Meaning |
| = |
x = 10 |
Assign value |
| += |
x += 5 |
x = x + 5 |
| -= |
x -= 3 |
x = x - 3 |
| *= |
x *= 2 |
x = x × 2 |
| /= |
x /= 2 |
x = x ÷ 2 |
5. Membership Operators
| Operator |
Meaning |
Example |
| in |
Checks if a value exists. |
"a" in "apple" |
| not in |
Checks if a value does not exist. |
"z" not in "apple" |
fruit = "apple"
print("a" in fruit)
print("z" in fruit)
print("z" not in fruit)
Classroom Activity
- Create two variables
a = 20 and b = 4.
- Perform all arithmetic operations.
- Compare the values using comparison operators.
- Use logical operators to combine conditions.
- Check whether the letter
"p" is present in the word "Python".
Lab Activity
Write a Python program that:
- Accepts two numbers from the user.
- Displays their sum, difference, product and quotient.
- Displays whether the first number is greater than the second.
- Displays whether both numbers are positive.
Quick Check
- What is an operator?
- Name any five types of operators.
- Which operator finds the remainder?
- What is the difference between
= and ==?
- Which logical operator returns True only if both conditions are True?
- What does the
in operator do?
Homework
- Write a Python program to perform all arithmetic operations on two numbers.
- Write a program using comparison operators.
- Write a program using logical operators.
- Write a program to check whether the letter
"o" is present in the word "Computer".
Assessment
| Assessment Method |
Description |
| Oral Questioning |
Operators and their types. |
| Worksheet |
Identify operators and predict outputs. |
| Programming Activity |
Write Python programs using different operators. |
Summary
In this session, you learned that operators are symbols used to perform operations on data. You explored five major types of Python operators: Arithmetic, Comparison, Logical, Assignment and Membership. These operators help programmers perform calculations, compare values, make decisions and manipulate data efficiently.