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.
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.-x negates x; not flag flips a boolean.a + b, a == b, a in L. Most operators are binary.| Family | Symbols |
|---|---|
| Arithmetic | + - * / // % ** |
| Relational | == != > < >= <= |
| Logical | and or not |
| Assignment | = |
| Augmented | += -= *= /= //= %= **= |
| Identity | is is not |
| Membership | in not in |
& | ^ ~ << >>) exist but are not in the Class XI CS syllabus. Stick to the seven families above.Used for everyday maths on numbers (int, float, complex). Some operators also work on strings and lists in special ways.
| Op | Meaning | Example | Result |
|---|---|---|---|
+ | Addition | 5 + 2 | 7 |
- | Subtraction | 5 - 2 | 3 |
* | Multiplication | 5 * 2 | 10 |
/ | True division | 5 / 2 | 2.5 |
// | Floor division | 5 // 2 | 2 |
% | Modulus (remainder) | 5 % 2 | 1 |
** | Exponentiation | 5 ** 2 | 25 |
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./ 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).Compare two values. Always return True or False.
| Op | Meaning | Example | Result |
|---|---|---|---|
== | Equal to | 5 == 5 | True |
!= | Not equal to | 5 != 6 | True |
> | Greater than | 5 > 2 | True |
< | Less than | 5 < 2 | False |
>= | Greater or equal | 3 >= 3 | True |
<= | Less or equal | 3 <= 2 | False |
Python allows chained comparisons:
1 < x < 10 means (1 < x) and (x < 10). Reads naturally and saves typing.Combine boolean values to form complex conditions.
| Op | True when… |
|---|---|
and | both sides are True |
or | at least one side is True |
not | operand is False (it flips True ↔ False) |
marks = 47 att = 80 if marks >= 33 and att >= 75: print("Pass") else: print("Fail")Output:
Pass — both halves are True.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)
= in a condition: if x = 5:. Use the double == for comparison. Single = is assignment.(marks >= 33) and (att >= 75) with brackets is easier to read than the same expression without.=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
Combines an arithmetic operation with assignment. x += 5 is short for x = x + 5.
| Op | Same 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)
++ or -- operators. x++ is a syntax error. Use x += 1 or x -= 1 instead.is / is notTests 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.in / not inTests 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) # FalseFor dictionaries,
in looks at keys, not values. Use in d.values() to check values.not in rather than not (x in L). Both work, but not in reads more naturally and is the recommended Python style.When several operators appear in one expression, Python applies them in a fixed order. Higher-precedence operators run first.
| Level | Operators |
|---|---|
| 1. Parentheses | ( ) |
| 2. Exponent | ** — right-to-left |
| 3. Unary | +x, -x |
| 4. Multiply & divide | * / // % |
| 5. Add & subtract | + - |
| 6. Comparisons | == != > < >= <= in is |
7. not | logical NOT |
8. and | logical AND |
9. or | logical OR |
| 10. Assignment | = += -= ... (always last) |
10 + 3 * 2 ** 2 = 10 + 3 * 4 # ** first = 10 + 12 # * next = 22 # + last
**:
2 ** 3 ** 2
= 2 ** (3 ** 2)
= 2 ** 9
= 512 # NOT 64True or False and False = True or (False and False) # and first = True or False = True
(a + b) * c is always clearer than a + b * c, even when both happen to give the same answer.3 + 4 == 7 evaluates as (3 + 4) == 7 — True. Comparisons run after arithmetic. Add brackets if you mean something else.2 ** 3 ** 2 is:
10 % 4:
"a" in "apple" evaluates to:
x = x + 7?
3 == 3.0 evaluates to:
print(20 // 6) print(20 % 6)Output:
print(2 + 3 * 4) print((2 + 3) * 4)Output:
a = 10
a += 5
a //= 3
print(a)
Output: print("py" * 2 + "thon")Output:
print(True or False and False) print(not 0)Output:
x = 5 print(1 < x < 10) print(x != 5 or x > 0)Output:
a = [1, 2, 3] b = a c = [1, 2, 3] print(a is b, a is c)Output:
d = {"a": 1, "b": 2}
print("a" in d, 1 in d)
Output: Each snippet has exactly one error. Mark the line number and write the corrected line.
1 x = 5 2 if x = 5: 3 print("five")Wrong line: Correction:
1 count = 10
2 count++
3 print(count)
Wrong line: Correction: 1 s = "hello" 2 if "x" not in s: 3 print("missing")Wrong line: Correction:
1 result = None 2 if result == None: 3 print("empty")Wrong line: Correction:
1 marks = 50 2 if marks >= 33 AND marks <= 100: 3 print("valid")Wrong line: Correction:
1 a = 7 2 a =+ 3 3 print(a) 4 # Expected 10 (after a += 3), got 3Wrong line: Correction:
/, // and % with one example each.
== and is? Give one example where they give different results.
True or False and False.
in operator check on a dictionary? Give a 2-line example.
Each program should read input from the user (where required) and produce a clear output. Use a separate sheet if you need more space.
// and % to print each digit on a separate line. (For 4729 the output should be 4, 7, 2, 9.)
and operator with %.
a < b < c holds (a strictly increasing sequence). Use a chained comparison.
in operator.
SI = (P * R * T) / 100 and the final amount A = P + SI using augmented assignment. Print SI and A both.