Grade VII Computer Science

Chapter 7 : More on Python

Session 1 : Operators & Types of Operators

Learning Objectives

After completing this lesson, students will be able to:

Prerequisite Knowledge

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

  1. Create two variables a = 20 and b = 4.
  2. Perform all arithmetic operations.
  3. Compare the values using comparison operators.
  4. Use logical operators to combine conditions.
  5. Check whether the letter "p" is present in the word "Python".

Lab Activity

Write a Python program that:

Quick Check

  1. What is an operator?
  2. Name any five types of operators.
  3. Which operator finds the remainder?
  4. What is the difference between = and ==?
  5. Which logical operator returns True only if both conditions are True?
  6. What does the in operator do?

Homework

  1. Write a Python program to perform all arithmetic operations on two numbers.
  2. Write a program using comparison operators.
  3. Write a program using logical operators.
  4. 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.