Computer Science

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.

Definition: An operator is a symbol used to perform operations such as arithmetic calculations, comparisons, logical operations, assignments, and membership testing.

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
+Addition10 + 515
-Subtraction10 - 55
*Multiplication10 * 550
/Division10 / 52.0
//Floor Division17 // 53
%Modulus17 % 52
**Exponent2 ** 38

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 To5 == 5
!=Not Equal To5 != 3
>Greater Than10 > 5
<Less Than5 < 10
>=Greater Than or Equal To5 >= 5
<=Less Than or Equal To3 <= 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
andTrue if both conditions are Truex > 5 and y > 5
orTrue if at least one condition is Truex > 5 or y > 50
notReverses the resultnot(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
TrueTrueTrueTrue
TrueFalseFalseTrue
FalseTrueFalseTrue
FalseFalseFalseFalse

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
isReturns True if both variables refer to the same object.
is notReturns True if both variables refer to different objects.

Example


a = 10
b = 10

print(a is b)

CBSE Note: For beginners, remember that == 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
inReturns True if the value is present.
not inReturns 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 is instead of == for value comparison.
  • Confusing and with or.
  • 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 == and is.
  • Understand logical operator truth tables.

CBSE Important Questions

2 Marks

  1. Differentiate between / and //.
  2. Differentiate between == and is.

3 Marks

  1. Explain Arithmetic and Relational operators with suitable examples.
  2. Write a program demonstrating Membership operators.

5 Marks

  1. Explain all Python operators with suitable examples and outputs.

Practice Yourself

  1. Write a program demonstrating all Arithmetic operators.
  2. Find the output of five expressions using Relational operators.
  3. Create a program using Logical operators to determine voting eligibility.
  4. Write a program using Membership operators with a list.
  5. 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.