Chapter 10 — Python Operators

Easy-language Notes · Part 1 of 2 (families · arithmetic · relational · logical)
REVISION NOTES
Class XI · Computer Science (083)
Sheet 1 (Front)

1. What is an Operator? · Seven Families

An operator is a symbol or short keyword that tells Python to perform a specific action on values. The values it works on are called operands.

In maths you write 5 + 3. The + is the operator, the 5 and 3 are operands. Python uses the same idea, just with a few extra symbols for things maths doesn't have, like comparing two values or testing if an item is inside a list.

Unary vs Binary

  • Unary — works on one operand. Example: -x negates x; not flag flips a boolean.
  • Binary — works on two operands. Example: a + b, a == b, a in L. Most operators are binary.

The Seven Families

FamilySymbols
Arithmetic+   -   *   /   //   %   **
Relational==   !=   >   <   >=   <=
Logicaland   or   not
Assignment=
Augmented+=   -=   *=   /=   //=   %=   **=
Identityis   is not
Membershipin   not in
Bitwise operators (& | ^ ~ << >>) exist but are not in the Class XI CS syllabus. Stick to the seven families above.

2. Arithmetic Operators

Used for everyday maths on numbers (int, float, complex). Some operators also work on strings and lists in special ways.

OpMeaningExampleResult
+Addition5 + 27
-Subtraction5 - 23
*Multiplication5 * 210
/True division5 / 22.5
//Floor division5 // 22
%Modulus (remainder)5 % 21
**Exponentiation5 ** 225
Three division operators side-by-side:
print(13 / 4)    # 3.25  (float result)
print(13 // 4)   # 3     (drops decimal)
print(13 % 4)    # 1     (remainder)
+ and * on strings and lists:
print("py" + "thon")   # python (concat)
print("ab" * 3)        # ababab (repeat)
print([1, 2] + [3])   # [1, 2, 3]
print([0] * 4)        # [0, 0, 0, 0]
-, /, %, ** do not work on strings or lists — TypeError.
When dividing two integers, / always gives a float in Python 3 (even if it looks like a clean answer). 10 / 2 is 5.0, not 5.
% is great for even/odd tests (n % 2 == 0 → even) and divisibility checks (n % 7 == 0 → multiple of 7).

3. Relational & Logical Operators

Relational (Comparison)

Compare two values. Always return True or False.

OpMeaningExampleResult
==Equal to5 == 5True
!=Not equal to5 != 6True
>Greater than5 > 2True
<Less than5 < 2False
>=Greater or equal3 >= 3True
<=Less or equal3 <= 2False

Python allows chained comparisons:

1 < x < 10 means (1 < x) and (x < 10). Reads naturally and saves typing.

Logical Operators

Combine boolean values to form complex conditions.

OpTrue when…
andboth sides are True
orat least one side is True
notoperand is False (it flips True ↔ False)
Pass condition needing both marks AND attendance:
marks = 47
att   = 80
if marks >= 33 and att >= 75:
    print("Pass")
else:
    print("Fail")
Output: Pass — both halves are True.
Short-circuit evaluation:
x = 0
# Python checks left side first; if False,
# it does not even look at the right side.
print(x > 0 and 10 / x > 1)
# False  (no ZeroDivisionError)
A common error is using = in a condition: if x = 5:. Use the double == for comparison. Single = is assignment.
Mixed condition order matters less than clarity. (marks >= 33) and (att >= 75) with brackets is easier to read than the same expression without.

4. Assignment & Augmented Assignment

Plain assignment =

The single equals sign stores a value in a variable. The right side is evaluated first, then the result goes into the name on the left.

x = 5             # store 5 in x
y = x + 1         # compute x+1, store in y
a = b = c = 0     # chain: all three become 0
p, q = 3, 7       # multiple assignment
p, q = q, p       # swap, no temp variable

Augmented (compound) assignment

Combines an arithmetic operation with assignment. x += 5 is short for x = x + 5.

OpSame as…Example
+=x = x + …x += 5
-=x = x - …x -= 2
*=x = x * …x *= 3
/=x = x / …x /= 4
//=x = x // …x //= 2
%=x = x % …x %= 7
**=x = x ** …x **= 3
total = 100
total -= 25       # 75
total *= 2        # 150
total //= 7       # 21
print(total)
Python has no ++ or -- operators. x++ is a syntax error. Use x += 1 or x -= 1 instead.

Chapter 10 — Python Operators

Easy-language Notes · Part 2 of 2 (assignment · identity · membership · precedence)
REVISION NOTES
Class XI · Computer Science (083)
Sheet 1 (Back)

5. Identity & Membership

Identity — is / is not

Tests whether two names point to the same object in memory — not whether their values happen to look equal.

a = [1, 2, 3]
b = a              # b points to same list
c = [1, 2, 3]      # a fresh list, same content
print(a == b)      # True  (same content)
print(a == c)      # True  (same content)
print(a is b)      # True  (same object)
print(a is c)      # False (different objects)

Most common use: testing for None.

if result is None: — the recommended idiom. Don't write == None.

Membership — in / not in

Tests whether a value appears inside a sequence (string, list, tuple) or as a key inside a dictionary.

print("py" in "python")        # True
print(5 in [1, 2, 3])           # False
print("a" not in "hello")      # True

d = {"name": "Vivek", "age": 16}
print("name" in d)            # True (checks keys)
print("Vivek" in d)           # False
For dictionaries, in looks at keys, not values. Use in d.values() to check values.
Use not in rather than not (x in L). Both work, but not in reads more naturally and is the recommended Python style.

6. Operator Precedence (BODMAS for Python)

When several operators appear in one expression, Python applies them in a fixed order. Higher-precedence operators run first.

Precedence from highest (top) to lowest (bottom)

LevelOperators
1. Parentheses( )
2. Exponent** — right-to-left
3. Unary+x, -x
4. Multiply & divide*   /   //   %
5. Add & subtract+   -
6. Comparisons== != > < >= <= in is
7. notlogical NOT
8. andlogical AND
9. orlogical OR
10. Assignment= += -= ... (always last)
Apply precedence step-by-step:
10 + 3 * 2 ** 2
= 10 + 3 * 4       # ** first
= 10 + 12          # * next
= 22               # + last
Right-to-left for **:
2 ** 3 ** 2
= 2 ** (3 ** 2)
= 2 ** 9
= 512              # NOT 64
Logical operators precedence:
True or False and False
= True or (False and False)   # and first
= True or False
= True
Golden rule for exams: when in doubt, add brackets. (a + b) * c is always clearer than a + b * c, even when both happen to give the same answer.
Mistake to avoid: 3 + 4 == 7 evaluates as (3 + 4) == 7 — True. Comparisons run after arithmetic. Add brackets if you mean something else.

Chapter 10 Worksheet — Python Operators

Total: 50 marks  |  Time: 75 min
Name: Class/Sec: Roll No.: Date:

Section A — Multiple Choice (1 × 10 = 10)

  1. Which operator gives the remainder after division?
    (a) /(b) //(c) %(d) **
  2. The result of 2 ** 3 ** 2 is:
    (a) 64(b) 512(c) 6(d) Error
  3. Which is a logical operator?
    (a) ==(b) //(c) and(d) is
  4. Output of 10 % 4:
    (a) 2.5(b) 2(c) 0.4(d) 6
  5. Which operator returns True only if both sides are True?
    (a) or(b) and(c) not(d) ==
  6. The expression "a" in "apple" evaluates to:
    (a) True(b) False(c) "a"(d) Error
  7. Which is NOT a Python operator?
    (a) **(b) ++(c) //(d) !=
  8. Same as x = x + 7?
    (a) x++ 7(b) x =+ 7(c) x += 7(d) x.add(7)
  9. Which has the highest precedence?
    (a) **(b) *(c) +(d) and
  10. 3 == 3.0 evaluates to:
    (a) True(b) False(c) Error(d) None

Section B — Find the Output (1 × 8 = 8)

  1. print(20 // 6)
    print(20 % 6)
    Output:
  2. print(2 + 3 * 4)
    print((2 + 3) * 4)
    Output:
  3. a = 10
    a += 5
    a //= 3
    print(a)
    Output:
  4. print("py" * 2 + "thon")
    Output:
  5. print(True or False and False)
    print(not 0)
    Output:
  6. x = 5
    print(1 < x < 10)
    print(x != 5 or x > 0)
    Output:
  7. a = [1, 2, 3]
    b = a
    c = [1, 2, 3]
    print(a is b, a is c)
    Output:
  8. d = {"a": 1, "b": 2}
    print("a" in d, 1 in d)
    Output:

Section C — Find the Error (1 × 6 = 6)

Each snippet has exactly one error. Mark the line number and write the corrected line.

  1. 1  x = 5
    2  if x = 5:
    3      print("five")
    Wrong line:   Correction:
  2. 1  count = 10
    2  count++
    3  print(count)
    Wrong line:   Correction:
  3. 1  s = "hello"
    2  if "x" not in s:
    3      print("missing")
    Wrong line:   Correction:
  4. 1  result = None
    2  if result == None:
    3      print("empty")
    Wrong line:   Correction:
  5. 1  marks = 50
    2  if marks >= 33 AND marks <= 100:
    3      print("valid")
    Wrong line:   Correction:
  6. 1  a = 7
    2  a =+ 3
    3  print(a)
    4  # Expected 10 (after a += 3), got 3
    Wrong line:   Correction:

Section D — Short Answer (2 × 5 = 10)

  1. Differentiate between /, // and % with one example each.
  2. What is the difference between == and is? Give one example where they give different results.
  3. Explain the and, or, not logical operators. Show the result of True or False and False.
  4. What does the in operator check on a dictionary? Give a 2-line example.
  5. List any four augmented (compound) assignment operators with one example each.

Chapter 10 Worksheet — (continued)

Sheet 2 (Back)

Section E — Code Tasks (16 marks)

Each program should read input from the user (where required) and produce a clear output. Use a separate sheet if you need more space.

  1. (2) Write a Python program that reads two numbers and prints their sum, difference, product, quotient and remainder.
  2. (3) Read a 4-digit number from the user. Use // and % to print each digit on a separate line. (For 4729 the output should be 4, 7, 2, 9.)
  3. (2) Read a number and print whether it is divisible by both 3 and 7. Use the and operator with %.
  4. (3) Read three numbers a, b, c. Print whether the relation a < b < c holds (a strictly increasing sequence). Use a chained comparison.
  5. (3) Read a string and a single character from the user. Print the messages: "present" if the character appears in the string and "absent" otherwise. Use the in operator.
  6. (3) Read the principal P, rate R and time T. Compute simple interest SI = (P * R * T) / 100 and the final amount A = P + SI using augmented assignment. Print SI and A both.