Python Operators Class 11 CBSE Computer Science: Arithmetic, Relational, Logical, Assignment, Identity and Membership Operators
Class 11 · Computer Science
Python Operators (CBSE Class 11 Computer Science)
Operators are special symbols used to perform operations on variables and values. They help perform mathematical calculations, comparisons, logical decisions, assignments, and membership testing. Operators are one of the most frequently used concepts in Python programming.
Learning Objectives
- Understand Python Operators.
- Learn Arithmetic Operators.
- Learn Relational Operators.
- Understand Logical Operators.
- Learn Assignment and Augmented Assignment Operators.
- Understand Identity Operators.
- Understand Membership Operators.
What is an Operator?
An Operator is a symbol that performs a specific operation on one or more operands and produces a result.
Types of Python Operators
Python Operators
│
├── Arithmetic
├── Relational (Comparison)
├── Logical
├── Assignment
├── Augmented Assignment
├── Identity
└── Membership
1. Arithmetic Operators
Arithmetic operators perform mathematical calculations.
| Operator | Meaning | Example | Result |
|---|---|---|---|
| + | Addition | 10 + 5 | 15 |
| - | Subtraction | 10 - 5 | 5 |
| * | Multiplication | 10 * 5 | 50 |
| / | Division | 10 / 5 | 2.0 |
| // | Floor Division | 17 // 5 | 3 |
| % | Modulus | 17 % 5 | 2 |
| ** | Exponent | 2 ** 3 | 8 |
Example Program
a = 17
b = 5
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)
print(a % b)
print(a ** 2)
Output
22
12
85
3.4
3
2
289
2. Relational (Comparison) Operators
Relational operators compare two values and always return either True or False.
| Operator | Meaning | Example |
|---|---|---|
| == | Equal To | 5 == 5 |
| != | Not Equal To | 5 != 3 |
| > | Greater Than | 10 > 5 |
| < | Less Than | 5 < 10 |
| >= | Greater Than or Equal To | 5 >= 5 |
| <= | Less Than or Equal To | 3 <= 7 |
Example
x = 10
y = 20
print(x < y)
print(x == y)
Output
True
False
3. Logical Operators
Logical operators combine two or more conditions.
| Operator | Description | Example |
|---|---|---|
| and | True if both conditions are True | x > 5 and y > 5 |
| or | True if at least one condition is True | x > 5 or y > 50 |
| not | Reverses the result | not(x > 5) |
Example
age = 18
print(age >= 18 and age <= 60)
print(age < 18 or age > 60)
print(not(age == 18))
Output
True
False
False
Truth Table of Logical Operators
| A | B | A and B | A or B |
|---|---|---|---|
| True | True | True | True |
| True | False | False | True |
| False | True | False | True |
| False | False | False | False |
4. Assignment Operator
Assignment operators assign values to variables.
x = 25
5. Augmented Assignment Operators
Augmented assignment operators perform an operation and assignment in a single statement.
| Operator | Equivalent |
|---|---|
| += | x = x + 5 |
| -= | x = x - 5 |
| *= | x = x * 5 |
| /= | x = x / 5 |
| //= | x = x // 5 |
| %= | x = x % 5 |
| **= | x = x ** 5 |
Example
x = 10
x += 5
print(x)
Output
15
6. Identity Operators
Identity operators compare whether two variables refer to the same object in memory.
| Operator | Description |
|---|---|
| is | Returns True if both variables refer to the same object. |
| is not | Returns True if both variables refer to different objects. |
Example
a = 10
b = 10
print(a is b)
== compares values, whereas is checks object identity. In practical CBSE programs, use == for comparing numbers and strings unless identity checking is specifically required.
7. Membership Operators
Membership operators check whether a value exists in a sequence such as a string, list, or tuple.
| Operator | Description |
|---|---|
| in | Returns True if the value is present. |
| not in | Returns True if the value is not present. |
Example
name = "Python"
print("P" in name)
print("Z" not in name)
Output
True
True
Operator Precedence (Overview)
When an expression contains multiple operators, Python follows a precedence order. A detailed discussion is covered in the next chapter, but remember this simplified order:
()
**
*, /, //, %
+, -
Relational Operators
not
and
or
Think Like a Programmer
Predict the output.
a = 12
b = 5
print(a % b)
print(a // b)
print(a > b and b > 2)
print("th" in "Python")
Answer
2
2
True
True
Dry Run Example
Let's understand how Python executes the following program step by step.
Program
a = 17
b = 5
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)
print(a % b)
print(a ** 2)
Dry Run Table
| Step | Statement | Variable Values | Output |
|---|---|---|---|
| 1 | a = 17 | a = 17 | - |
| 2 | b = 5 | a = 17, b = 5 | - |
| 3 | print(a + b) | 17 + 5 | 22 |
| 4 | print(a - b) | 17 - 5 | 12 |
| 5 | print(a * b) | 17 × 5 | 85 |
| 6 | print(a / b) | 17 ÷ 5 | 3.4 |
| 7 | print(a // b) | 17 // 5 | 3 |
| 8 | print(a % b) | 17 % 5 | 2 |
| 9 | print(a ** 2) | 17² | 289 |
Output Prediction Challenge
Without executing the program, predict its output.
x = 12
y = 5
print(x // y)
print(x % y)
print(x > y)
print(x == y)
print(x != y)
Click to View Answer
2
2
True
False
True
Real-Life Example
- Arithmetic Operator → Calculating total marks.
- Relational Operator → Checking whether marks are greater than the passing marks.
- Logical Operator → Checking multiple conditions for scholarship eligibility.
- Membership Operator → Checking whether a student's name exists in a class list.
- Assignment Operator → Storing the calculated percentage.
Common Beginner Mistakes
- Using
=instead of==. - Confusing
/and//. - Using
isinstead of==for value comparison. - Confusing
andwithor. - Forgetting that
%returns the remainder.
Memory Tricks
- % → Remainder
- // → Quotient (Floor Division)
- ** → Power
- == → Compare Values
- is → Compare Identity
- in → Present?
Exam Tips
- Learn the purpose of every operator.
- Practice output-based questions.
- Remember the difference between
/and//. - Know the difference between
==andis. - Understand logical operator truth tables.
CBSE Important Questions
2 Marks
- Differentiate between
/and//. - Differentiate between
==andis.
3 Marks
- Explain Arithmetic and Relational operators with suitable examples.
- Write a program demonstrating Membership operators.
5 Marks
- Explain all Python operators with suitable examples and outputs.
Practice Yourself
- Write a program demonstrating all Arithmetic operators.
- Find the output of five expressions using Relational operators.
- Create a program using Logical operators to determine voting eligibility.
- Write a program using Membership operators with a list.
- Use Augmented Assignment operators to update a variable.
Frequently Asked Questions (FAQs)
1. What is an operator?
An operator is a symbol that performs an operation on one or more operands.
2. Which operator calculates the remainder?
The modulus operator (%).
3. Which operator checks whether a value exists in a list?
The in operator.
4. What is the difference between == and is?
== compares values, while is checks whether two variables refer to the same object.
5. Which operator is used to calculate powers?
The exponent operator (**).
Summary
- Python provides Arithmetic, Relational, Logical, Assignment, Augmented Assignment, Identity, and Membership operators.
- Arithmetic operators perform mathematical calculations.
- Relational operators compare values and return Boolean results.
- Logical operators combine multiple conditions.
- Assignment operators store values in variables.
- Identity operators compare object identity, while Membership operators check whether a value exists in a sequence.