⚠ यह कार्रवाई अनुमति नहीं है!
🐍 NIELIT O Level · M3-R5 Python · Hindi Notes

Chapter 4: Operators, Expressions & Statements — Python की गणित और तर्क शक्ति

Python के सभी 7 प्रकार के Operators — Arithmetic, Relational, Logical, Assignment, Bitwise, Membership व Identity — हर एक का हर operator अलग example के साथ! साथ में Operator Precedence की पूरी table, Expressions व Statements का अंतर, 40+ runnable examples, हर code में Copy व ▶ Run buttons।

📑 13 Sections 💻 40+ Python Examples ▶ Run in Compiler ❓ 50 MCQs + Output Qs 🗓 Updated 2026
👉 सभी chapters देखने के लिए swipe करें
📑 Table of Contents — किसी भी topic पर सीधे जाएँ
4.0

Operator क्या है? — Operand, Operator व उनके परिवार

Operator = वह symbol जो values पर कोई operation करे (+, -, ==, and...)। Operand = वे values जिन पर operation होता है। जैसे a + b में — a, b operands हैं और + operator। Chapter 3 में हमने tokens में operators का नाम सुना था — अब पूरा परिवार मिलेगा!

👨‍👩‍👧 Operators की गिनती के आधार पर 3 श्रेणियाँ

श्रेणीOperandsExample
Unary1 operand-x, not flag, ~n
Binary2 operandsa + b, x > y
Ternary3 हिस्सेa if a > b else b
🐍 Ternary Operator — एक line का if-else▶ Run
a, b = 15, 8
largest = a if a > b else b
print("Largest =", largest)
OUTPUTLargest = 15

🗂️ Python के 7 प्रकार के Operators (इस Chapter का नक्शा)

#TypeOperators
1Arithmetic+   −   *   /   //   %   **
2Relational==   !=   >   <   >=   <=
3Logicaland   or   not
4Assignment=   +=   −=   *=   /=   //=   %=   **=
5Bitwise&   |   ^   ~   <<   >>
6Membershipin   not in
7Identityis   is not
Exam Point: Operator symbol है, Operand value। Unary = 1 operand (-x, not); Binary = 2 (a+b); Ternary = value_if_true if condition else value_if_false। Python में कुल 7 प्रकार के operators।
4.1

Arithmetic Operators — गणित के 7 सिपाही

Mathematical calculations के operators — इनमें से / vs // और negative numbers पर // exam के सबसे tricky सवाल हैं!
OperatorनामExampleResult
+Addition7 + 310
Subtraction7 − 34
*Multiplication7 * 321
/Division (हमेशा float)7 / 23.5
//Floor Division7 // 23
%Modulus (remainder)7 % 21
**Exponent (power)2 ** 38
🐍 सातों एक साथ▶ Run
a, b = 17, 5
print("Add:", a + b)
print("Sub:", a - b)
print("Mul:", a * b)
print("Div:", a / b)          # float
print("Floor Div:", a // b)   # int quotient
print("Mod:", a % b)          # remainder
print("Power:", a ** 2)
OUTPUTAdd: 22
Sub: 12
Mul: 85
Div: 3.4
Floor Div: 3
Mod: 2
Power: 289

⚠️ Negative Floor Division — Exam Trap!

🐍 -10 // 3 = -3 नहीं, -4!▶ Run
print(10 // 3)     # 3.33 -> neeche -> 3
print(-10 // 3)    # -3.33 -> NEECHE ki taraf -> -4 !
print(-7 % 3)      # modulus ka sign divisor jaisa -> 2
OUTPUT3
-4
2
समझें: Floor का मतलब "नीचे की ओर" — number line पर -3.33 के नीचे -4 है (-3 नहीं!)। और Python में % का result हमेशा divisor के sign का होता है — -7 % 3 = 2 (क्योंकि -7 = 3×(-3) + 2)।

⚡ ** की खासियत — Right to Left!

🐍 2 ** 3 ** 2 = 512 (64 नहीं!)▶ Run
print(2 ** 3 ** 2)    # pehle 3**2 = 9, phir 2**9
print((2 ** 3) ** 2)  # brackets se order badla
OUTPUT512
64
Exam Point: / हमेशा float देता है (10/5 = 2.0!); // floor division (नीचे की ओर — -10//3 = -4); % remainder (sign divisor जैसा); ** right-to-left associative (2**3**2 = 512)।
4.2

Relational (Comparison) Operators — तुलना करने वाले

दो values की तुलना करके हमेशा True या False (boolean) देते हैं — if conditions व loops की जान यही हैं। Python की खास ताकत: Chaining (10 < x < 20)!
OperatorमतलबExample (a=10, b=5)Result
==बराबर है?a == bFalse
!=बराबर नहीं है?a != bTrue
>बड़ा है?a > bTrue
<छोटा है?a < bFalse
>=बड़ा या बराबर?a >= 10True
<=छोटा या बराबर?b <= 4False
🐍 Comparison Chaining — Python का जादू▶ Run
marks = 75
print(60 <= marks <= 80)     # kya marks 60-80 ke beech?
# dusri languages me likhna padta:
# marks >= 60 and marks <= 80

print("apple" < "banana")     # strings ki dictionary tulna!
OUTPUTTrue
True
समझें: Strings की तुलना dictionary order (alphabetical) में होती है — 'a' < 'b' इसलिए "apple" < "banana" True। ध्यान: uppercase letters की ASCII value छोटी होती है — "Apple" < "apple" भी True!
Exam Point: Relational operators हमेशा boolean (True/False) देते हैं। = assignment है, == comparison — इन्हें मिलाना सबसे common गलती! Chaining: 10 < x < 20 valid Python है।
4.3

Logical Operators — and, or, not की तिकड़ी

कई conditions को जोड़ने के लिए — and (दोनों true हों), or (कोई एक true हो), not (उल्टा कर दो)। छुपा हुआ राज़: ये boolean नहीं, असली values return करते हैं (short-circuit)!

📋 Truth Tables (रटने लायक)

ABA and BA or B
TrueTrueTrueTrue
TrueFalseFalseTrue
FalseTrueFalseTrue
FalseFalseFalseFalse
🐍 तीनों का उपयोग — eligibility check▶ Run
age = 20
has_id = True
print(age >= 18 and has_id)    # dono zaroori
print(age < 18 or has_id)      # koi ek kaafi
print(not has_id)              # ulta
OUTPUTTrue
True
False

⚡ Short-Circuit Evaluation — Python की चालाकी

🐍 and/or असली values लौटाते हैं!▶ Run
print(0 and 10)      # pehla falsy -> wahi lauta diya
print(5 and 10)      # pehla truthy -> DUSRA lauta diya
print(0 or 10)       # pehla falsy -> dusra dekha
print(5 or 10)       # pehla truthy -> wahi lauta, dusra dekha hi nahi!
OUTPUT0
10
10
5
Rule: and — पहला operand falsy हो तो वही return, वरना दूसरा। or — पहला truthy हो तो वही return, वरना दूसरा। इसे short-circuit कहते हैं क्योंकि answer तय होते ही Python आगे देखता ही नहीं — 10/0 जैसी error से भी बच सकते हैं: x != 0 and 10/x
Exam Point: Truth tables; short-circuit — and में पहला False तो दूसरा evaluate नहीं, or में पहला True तो दूसरा नहीं। Falsy values: 0, "", None, False, खाली list — बाकी सब truthy। "5 and 10" का answer 10 (True नहीं!)।
4.4

Assignment Operators — Value देने वाले shortcuts

= value assign करता है; बाकी सब augmented operators हैं — "operation करो और वापस उसी में रखो" के shortcuts। x += 5 यानी x = x + 5
OperatorExampleबराबर हैx=10 पर Result
=x = 1010
+=x += 3x = x + 313
−=x −= 3x = x − 37
*=x *= 3x = x * 330
/=x /= 3x = x / 33.333…
//=x //= 3x = x // 33
%=x %= 3x = x % 31
**=x **= 2x = x ** 2100
🐍 Shopping bill में augmented operators▶ Run
total = 0
total += 250     # pehla item
total += 120     # dusra item
total -= 50      # discount
total *= 1.18    # 18% GST laga
print(f"Final Bill: Rs. {round(total, 2)}")
OUTPUTFinal Bill: Rs. 377.6
Exam Point: x += 5 ⟺ x = x + 5 (सभी augmented forms यही pattern)। Python में x++ या ++x नहीं होता — यह C/Java की चीज़ है, Python में x += 1 लिखते हैं!
4.5

Bitwise Operators — Binary bits पर सीधा काम

ये operators numbers को binary (bits) में बदलकर हर bit पर operation करते हैं। Chapter 3 में हमने 0b binary literals देखे थे — अब उन bits से खेलेंगे! Example में a = 10 (1010), b = 4 (0100)।
OperatorनामRulea=10, b=4
&ANDदोनों bits 1 हों तो 11010 & 0100 = 0000 → 0
|ORकोई एक bit 1 हो तो 11010 | 0100 = 1110 → 14
^XORbits अलग हों तो 11010 ^ 0100 = 1110 → 14
~NOT~n = −(n+1)~10 → −11
<<Left Shift× 2 हर shift पर10 << 2 → 40
>>Right Shift÷ 2 हर shift पर10 >> 2 → 2
🐍 सभी bitwise एक साथ▶ Run
a, b = 10, 4        # 1010, 0100
print("AND :", a & b)
print("OR  :", a | b)
print("XOR :", a ^ b)
print("NOT :", ~a)          # -(10+1) = -11
print("Left Shift :", a << 2)   # 10 x 4 = 40
print("Right Shift:", a >> 2)   # 10 / 4 = 2
OUTPUTAND : 0
OR : 14
XOR : 14
NOT : -11
Left Shift : 40
Right Shift: 2
Shift की trick: हर left shift = ×2 (10<<1=20, 10<<2=40); हर right shift = ÷2 (integer) (10>>1=5, 10>>2=2)। और ~n का formula सीधा याद रखें: −(n+1) — ~5 = −6, ~(−3) = 2।
Exam Point: & | ^ की bit rules; ~n = −(n+1); n<<k = n × 2ᵏ; n>>k = n ÷ 2ᵏ। XOR की पहचान — same bits = 0, अलग bits = 1 (इसीलिए a^a = 0 हमेशा)।
4.6

Membership व Identity Operators — in और is की जोड़ी

🔍 Membership — in, not in

check करते हैं कि कोई value sequence (string/list/tuple) के अंदर है या नहीं — result हमेशा True/False।
🐍 in / not in▶ Run
text = "Boosting Skills"
print("Skill" in text)
print("Java" in text)
print("Java" not in text)

fruits = ["apple", "mango", "banana"]
print("mango" in fruits)
OUTPUTTrue
False
True
True

🆔 Identity — is, is not (vs ==)

== पूछता है "क्या values बराबर हैं?"; is पूछता है "क्या दोनों memory में एक ही object हैं?" (id() same?)। Chapter 3 के object-reference model का सीधा उपयोग!
🐍 == True लेकिन is False — कैसे?▶ Run
list1 = [1, 2, 3]
list2 = [1, 2, 3]      # same values, ALAG object
list3 = list1           # wahi object

print(list1 == list2)   # values same? True
print(list1 is list2)   # object same? False!
print(list1 is list3)   # True — ek hi object ke 2 naam
OUTPUTTrue
False
True
Exam Point: in/not in = membership (sequence के अंदर?); is/is not = identity (same object? id() से जुड़ा); == = equality (values same?)। "== True पर is False" वाला list example exam favourite है। None की जाँच हमेशा x is None से करते हैं।
4.7

Operator Precedence व Associativity — पहले कौन चलेगा?

एक expression में कई operators हों तो Precedence तय करती है पहले कौन चले; same precedence पर Associativity (left-to-right या right-to-left) direction बताती है।

Precedence Ladder — ऊपर वाला पहले चलता है

1. ( ) Parentheses — सबसे पहले 2. ** Exponent (Right → Left!) 3. ~ +x −x (Unary) 4. * / // % 5. + − (Binary) 6. << >> फिर & ^ | (Bitwise) 7. == != > < in is (Comparison) 8. not → and → or — सबसे आखिर में
🐍 Precedence को step-by-step देखिए▶ Run
result = 5 + 2 * 3 ** 2 - 4 / 2
# Step 1: 3 ** 2 = 9        (exponent pehle)
# Step 2: 2 * 9 = 18        (* aur / same level)
# Step 3: 4 / 2 = 2.0
# Step 4: 5 + 18 - 2.0 = 21.0
print(result)

print(True or False and False)   # and pehle! True or (False) = True
OUTPUT21.0
True
Logical याद रखें: not > and > or — इसलिए True or False and False में पहले and (False), फिर or → True। Confusion से बचना हो तो brackets लगाइए — यही best practice है!
Exam Point: क्रम — () → ** → unary → * / // % → + − → shifts/bitwise → comparison → not → and → or। ** अकेला right-to-left है; बाकी सब left-to-right। "True or False and False" = True (and पहले)।
4.8

Expressions व Statements — Value देने वाले vs काम करने वाले

Expression = operands + operators का combination जो एक value produce करे (2+3, a*b, x>5)। Statement = पूरा instruction जो कोई action करे (x = 5, if, for) — ज़रूरी नहीं कि value दे।
आधारExpressionStatement
क्या करता हैValue produce करता हैAction perform करता है
Example2 + 3, a * b, x > 5x = 5, if..., for..., print(x)
Variable में रख सकते हैं?हाँ — y = 2 + 3नहीं — y = (x = 5) ✘ Error
सम्बन्धStatement का हिस्सा हो सकता हैExpressions से मिलकर बनता है

🧩 Types of Expressions

🐍 4 तरह के expressions▶ Run
a, b = 8, 3
print(a + b * 2)          # Arithmetic expression
print(a > b)              # Relational expression
print(a > 5 and b < 5)    # Logical expression
print("Py" + "thon")      # String expression
OUTPUT14
True
True
Python

📜 Types of Statements

  • Assignment statement: x = 10
  • Conditional statement: if, elif, else (Chapter 2 में देखे)
  • Looping statement: for, while
  • Control statements: break, continue, pass
  • Compound statement: header + indented block (if/for/def का पूरा block)
Exam Point: Expression value देता है, Statement action करता है। हर expression को statement बना सकते हैं (expression statement), पर हर statement expression नहीं। if/for = compound statements (header : + indented body)।
4.9

🎯 Output-Based Questions — Operators के Tricky सवाल

Operator precedence व short-circuit के questions exam में सबसे ज़्यादा गलत होते हैं — यहीं practice कर लो तो exam में full marks!

Q1. / vs // vs %

🐍 Output बताइए▶ Run
print(15 / 4)
print(15 // 4)
print(15 % 4)
ANSWER3.75
3
3
← / float देता है; // quotient; % remainder।

Q2. Negative Floor Division

🐍 Output बताइए▶ Run
print(-17 // 5)
print(-17 % 5)
ANSWER-4
3
← -3.4 नीचे की ओर = -4; remainder = -17 - (5 × -4) = 3 (sign divisor जैसा)।

Q3. ** की Right Associativity

🐍 Output बताइए▶ Run
print(2 ** 2 ** 3)
ANSWER256
← Right से: 2**3 = 8, फिर 2**8 = 256 (64 नहीं!)।

Q4. Precedence Mix

🐍 Output बताइए▶ Run
print(10 - 4 * 2 + 6 // 3)
ANSWER4
← पहले 4*2=8 और 6//3=2; फिर 10-8+2 = 4।

Q5. Short-Circuit Values

🐍 Output बताइए▶ Run
print(4 and 7)
print(0 or "Hello")
print("" and 100)
ANSWER7
Hello
(खाली string)
← and: पहला truthy तो दूसरा; or: पहला falsy तो दूसरा; "" falsy है तो and ने वही लौटाया।

Q6. Logical Precedence

🐍 Output बताइए▶ Run
print(not True and False)
print(not (True and False))
ANSWERFalse
True
← पहली line: not True = False, फिर False and False = False; दूसरी में bracket पहले — and का False, फिर not = True।

Q7. Bitwise की गिनती

🐍 Output बताइए▶ Run
print(6 & 3)
print(6 | 3)
print(6 ^ 3)
ANSWER2
7
5
← 110 & 011 = 010(2); 110 | 011 = 111(7); 110 ^ 011 = 101(5)।

Q8. Shift Operators

🐍 Output बताइए▶ Run
print(5 << 3)
print(80 >> 2)
print(~7)
ANSWER40
20
-8
← 5×2³=40; 80÷2²=20; ~n = -(n+1) = -8।

Q9. Chained Comparison

🐍 Output बताइए▶ Run
x = 15
print(10 < x < 20)
print(10 < x > 20)
ANSWERTrue
False
← पहली: 10<15 और 15<20 दोनों true; दूसरी: 15>20 false — chaining में सब true होने चाहिए।

Q10. is vs ==

🐍 Output बताइए▶ Run
a = [10, 20]
b = [10, 20]
c = a
print(a == b, a is b)
print(a == c, a is c)
ANSWERTrue False
True True
← a, b की values same पर objects अलग; c तो a का ही दूसरा नाम है।

Q11. Augmented Assignment Chain

🐍 Output बताइए▶ Run
x = 8
x //= 3
x **= 2
x += 1
print(x)
ANSWER5
← 8//3 = 2 → 2**2 = 4 → 4+1 = 5।

Q12. Membership + Logical Combo

🐍 Output बताइए▶ Run
s = "python"
print("p" in s and "z" not in s)
print("P" in s)
ANSWERTrue
False
← "p" है और "z" नहीं है — दोनों true। "P" (capital) नहीं है — case-sensitive!
4.10

💻 Practice Programs — Operators का असली उपयोग

हर program इस chapter के operators पर — arithmetic से calculator, bitwise से even/odd, XOR से swap जैसी नई tricks!

Program 1 — Simple Calculator (सभी arithmetic)

🐍 calculator.py▶ Run
a = float(input("Pehla number: "))
b = float(input("Dusra number: "))
print(f"Sum        = {a + b}")
print(f"Difference = {a - b}")
print(f"Product    = {a * b}")
print(f"Division   = {a / b}")
print(f"Floor Div  = {a // b}")
print(f"Remainder  = {a % b}")
print(f"Power      = {a ** b}")
OUTPUT (inputs: 9, 2)Sum = 11.0
Difference = 7.0
Product = 18.0
Division = 4.5
Floor Div = 4.0
Remainder = 1.0
Power = 81.0

Program 2 — Bitwise से Even/Odd (नई trick!)

🐍 bitwise_even_odd.py — % की जगह &▶ Run
n = int(input("Number: "))
if n & 1:
    print("Odd")       # aakhri bit 1 = odd
else:
    print("Even")      # aakhri bit 0 = even
OUTPUT (input: 14)Even

Program 3 — XOR से Swap (temp भी नहीं, comma भी नहीं!)

🐍 xor_swap.py▶ Run
a, b = 25, 60
a = a ^ b
b = a ^ b     # (a^b)^b = a
a = a ^ b     # (a^b)^a = b
print("a =", a, ", b =", b)
OUTPUTa = 60 , b = 25
← XOR का जादू: x^y^y = x हमेशा!

Program 4 — Voting Eligibility (logical operators)

🐍 voting.py▶ Run
age = int(input("Age: "))
citizen = input("Indian citizen? (yes/no): ")
eligible = age >= 18 and citizen == "yes"
print("Vote de sakte hain!" if eligible else "Abhi eligible nahi.")
OUTPUT (inputs: 19, yes)Vote de sakte hain!

Program 5 — Discount Calculator (chained comparison)

🐍 discount.py▶ Run
amount = float(input("Bill amount: "))
if amount >= 5000:
    discount = 20
elif 2000 <= amount < 5000:      # chaining!
    discount = 10
elif 500 <= amount < 2000:
    discount = 5
else:
    discount = 0
final = amount - (amount * discount / 100)
print(f"Discount: {discount}% | Final: Rs. {final}")
OUTPUT (input: 3000)Discount: 10% | Final: Rs. 2700.0

Program 6 — Seconds को HH:MM:SS में (// और %)

🐍 time_convert.py▶ Run
total = int(input("Total seconds: "))
hours = total // 3600
minutes = (total % 3600) // 60
seconds = total % 60
print(f"{hours} hr : {minutes} min : {seconds} sec")
OUTPUT (input: 7385)2 hr : 3 min : 5 sec

Program 7 — Power Table (** का उपयोग)

🐍 power_table.py▶ Run
n = int(input("Number: "))
for p in range(1, 6):
    print(f"{n} ^ {p} = {n ** p}")
OUTPUT (input: 3)3 ^ 1 = 3
3 ^ 2 = 9
3 ^ 3 = 27
3 ^ 4 = 81
3 ^ 5 = 243

Program 8 — Password Strength (membership + logical)

🐍 password_check.py▶ Run
pwd = input("Password: ")
has_digit = any(ch in "0123456789" for ch in pwd)
has_special = "@" in pwd or "#" in pwd or "$" in pwd
long_enough = len(pwd) >= 8

if has_digit and has_special and long_enough:
    print("Strong password ✔")
else:
    print("Weak password — digit, @/#/$ aur 8+ length rakhein")
OUTPUT (input: boost@123)Strong password ✔
Exam Point: n & 1 से even/odd; XOR swap; // व % से time conversion; chained comparison in elif — ये patterns practical में impress करते हैं और theory में differentiate!
4.11

Summary — Quick Revision (Exam से पहले पढ़ें)

  • Operator = symbol, Operand = value; Unary (1), Binary (2), Ternary (a if cond else b)।
  • 7 प्रकार: Arithmetic, Relational, Logical, Assignment, Bitwise, Membership, Identity।
  • Arithmetic: / हमेशा float; // floor (नीचे — -10//3 = -4); % का sign divisor जैसा; ** right-to-left (2**3**2 = 512)।
  • Relational: हमेशा True/False; chaining valid (10 < x < 20); strings dictionary order में।
  • Logical: not > and > or; short-circuit — and/or असली values लौटाते हैं (5 and 10 → 10; 5 or 10 → 5)।
  • Assignment: x += 5 ⟺ x = x+5; Python में ++ / -- नहीं होता।
  • Bitwise: & | ^ bits पर; ~n = −(n+1); n<<k = n×2ᵏ; n>>k = n÷2ᵏ; a^a = 0।
  • Membership: in / not in (sequence में?); Identity: is / is not (same object? — == से अलग!)।
  • Precedence: () → ** → unary → * / // % → + − → bitwise → comparison → not → and → or।
  • Expression value देता है (2+3); Statement action करता है (x = 5, if, for); compound statement = header + indented block।
4.12

Model Questions — 50 MCQs + 15 Theory Questions

❓ A. Multiple Choice Questions (50)

#प्रश्न
1

a + b में a और b क्या कहलाते हैं?

(a) Operators(b) Operands(c) Keywords(d) Literals
✔ सही उत्तर: (b) Operands+ operator है; जिन values पर operation हो वे operands।
2

केवल 1 operand वाला operator कहलाता है —

(a) Binary(b) Ternary(c) Unary(d) Single
✔ सही उत्तर: (c) Unaryजैसे -x, not flag, ~n।
3

a if a > b else b किस operator का उदाहरण है?

(a) Unary(b) Binary(c) Ternary(d) Logical
✔ सही उत्तर: (c) Ternaryएक line का if-else — 3 हिस्से होते हैं।
4

Python में operators के कितने मुख्य प्रकार हैं?

(a) 4(b) 5(c) 7(d) 10
✔ सही उत्तर: (c) 7Arithmetic, Relational, Logical, Assignment, Bitwise, Membership, Identity।
5

10 / 5 का output क्या होगा?

(a) 2(b) 2.0(c) 5(d) Error
✔ सही उत्तर: (b) 2.0/ हमेशा float देता है — पूरा divide होने पर भी।
6

17 // 5 का मान है —

(a) 3.4(b) 3(c) 4(d) 2
✔ सही उत्तर: (b) 3Floor division — quotient का पूर्णांक भाग।
7

-10 // 3 का output —

(a) -3(b) -4(c) 3(d) -3.33
✔ सही उत्तर: (b) -4-3.33 को नीचे की ओर round किया जाता है — -4।
8

17 % 5 का मान —

(a) 3(b) 2(c) 3.4(d) 12
✔ सही उत्तर: (b) 217 = 5×3 + 2 — remainder 2।
9

2 ** 3 ** 2 का output —

(a) 64(b) 512(c) 36(d) 12
✔ सही उत्तर: (b) 512** right-to-left है — पहले 3**2=9, फिर 2**9=512।
10

कौन-सा operator power (घात) निकालता है?

(a) ^(b) **(c) //(d) %%
✔ सही उत्तर: (b) **^ Python में XOR है, power नहीं!
11

Relational operators का result हमेशा होता है —

(a) int(b) float(c) True/False(d) string
✔ सही उत्तर: (c) True/FalseBoolean values — इसीलिए conditions में उपयोग होते हैं।
12

= और == में अंतर —

(a) दोनों same(b) = assignment, == comparison(c) = comparison, == assignment(d) दोनों गलत
✔ सही उत्तर: (b) = assignment, == comparisonif x = 5 लिखना SyntaxError है!
13

x = 15 हो तो 10 < x < 20 का output —

(a) True(b) False(c) Error(d) 15
✔ सही उत्तर: (a) TrueChaining — दोनों comparisons true हैं।
14

"Apple" < "apple" का output —

(a) False(b) True(c) Error(d) 0
✔ सही उत्तर: (b) TrueUppercase की ASCII value छोटी होती है (A=65, a=97)।
15

कौन-सा operator "बराबर नहीं" check करता है?

(a) <>(b) !=(c) ==(d) not
✔ सही उत्तर: (b) !=<> पुराने Python 2 में था, अब नहीं चलता।
16

True and False का मान —

(a) True(b) False(c) 1(d) Error
✔ सही उत्तर: (b) Falseand में दोनों true होने चाहिए।
17

False or True का मान —

(a) False(b) True(c) 0(d) None
✔ सही उत्तर: (b) Trueor में कोई एक true काफी है।
18

not (5 > 3) का output —

(a) True(b) False(c) 5(d) Error
✔ सही उत्तर: (b) False5>3 True है, not से उल्टा — False।
19

print(3 and 8) का output —

(a) True(b) 3(c) 8(d) False
✔ सही उत्तर: (c) 8and में पहला truthy हो तो दूसरा operand return होता है।
20

print(0 or 7) का output —

(a) 0(b) 7(c) True(d) False
✔ सही उत्तर: (b) 7or में पहला falsy (0) हो तो दूसरा return होता है।
21

Short-circuit में "and" का दूसरा operand check नहीं होता जब —

(a) पहला True हो(b) पहला False हो(c) दोनों True हों(d) कभी नहीं
✔ सही उत्तर: (b) पहला False होFalse and X — answer False ही रहेगा, X देखने की ज़रूरत नहीं।
22

इनमें से falsy value नहीं है —

(a) 0(b) ""(c) None(d) "0"
✔ सही उत्तर: (d) "0""0" एक non-empty string है — truthy!
23

x += 5 बराबर है —

(a) x = 5(b) x = x + 5(c) x + 5(d) x == 5
✔ सही उत्तर: (b) x = x + 5Augmented assignment operator।
24

Python में x++ लिखने पर —

(a) x बढ़ जाता है(b) SyntaxError(c) x घट जाता है(d) 0 हो जाता है
✔ सही उत्तर: (b) SyntaxErrorPython में ++/-- नहीं होते — x += 1 लिखते हैं।
25

x = 10; x //= 3 के बाद x —

(a) 3.33(b) 3(c) 1(d) 30
✔ सही उत्तर: (b) 3x = 10 // 3 = 3।
26

x = 4; x **= 2 के बाद x —

(a) 8(b) 16(c) 6(d) 2
✔ सही उत्तर: (b) 16x = 4 ** 2 = 16।
27

Bitwise AND operator है —

(a) and(b) &&(c) &(d) AND
✔ सही उत्तर: (c) &and logical है; && Python में नहीं होता।
28

6 & 3 का output — (110 & 011)

(a) 7(b) 2(c) 5(d) 9
✔ सही उत्तर: (b) 2110 & 011 = 010 = 2 (दोनों 1 हों तभी 1)।
29

6 | 3 का output —

(a) 7(b) 2(c) 5(d) 3
✔ सही उत्तर: (a) 7110 | 011 = 111 = 7 (कोई एक 1 हो तो 1)।
30

6 ^ 3 का output —

(a) 7(b) 5(c) 2(d) 216
✔ सही उत्तर: (b) 5110 ^ 011 = 101 = 5 (bits अलग हों तो 1)। ^ power नहीं है!
31

~5 का मान —

(a) 5(b) -5(c) -6(d) 4
✔ सही उत्तर: (c) -6Formula: ~n = -(n+1)।
32

4 << 2 का output —

(a) 8(b) 16(c) 1(d) 6
✔ सही उत्तर: (b) 16हर left shift ×2 — 4×2² = 16।
33

32 >> 3 का output —

(a) 4(b) 8(c) 256(d) 29
✔ सही उत्तर: (a) 432 ÷ 2³ = 4।
34

a ^ a का मान हमेशा —

(a) a(b) 2a(c) 0(d) 1
✔ सही उत्तर: (c) 0Same bits XOR में cancel हो जाते हैं — XOR swap इसी पर आधारित।
35

Membership operator कौन-से हैं?

(a) is, is not(b) in, not in(c) and, or(d) ==, !=
✔ सही उत्तर: (b) in, not inSequence में value की जाँच के लिए।
36

"a" in "apple" का output —

(a) True(b) False(c) 1(d) a
✔ सही उत्तर: (a) True"a" string "apple" में मौजूद है।
37

is operator तुलना करता है —

(a) Values की(b) Object identity (memory) की(c) Types की(d) Length की
✔ सही उत्तर: (b) Object identity कीid() same है या नहीं — == values देखता है।
38

a=[1,2]; b=[1,2] हो तो a is b —

(a) True(b) False(c) Error(d) [1,2]
✔ सही उत्तर: (b) FalseValues same पर memory में दो अलग objects — a == b True होगा।
39

None की जाँच का सही तरीका —

(a) x == None(b) x is None(c) x = None(d) None in x
✔ सही उत्तर: (b) x is NoneIdentity check — यही Pythonic best practice है।
40

सबसे ऊँची precedence किसकी है?

(a) **(b) ( )(c) *(d) or
✔ सही उत्तर: (b) ( )Parentheses सबसे पहले — फिर **।
41

सबसे नीची precedence (दिए गए में) —

(a) and(b) not(c) or(d) ==
✔ सही उत्तर: (c) orक्रम: not → and → or (or सबसे बाद में)।
42

2 + 3 * 4 का output —

(a) 20(b) 14(c) 24(d) 9
✔ सही उत्तर: (b) 14* की precedence + से ऊँची — पहले 3×4।
43

True or False and False का output —

(a) False(b) True(c) Error(d) None
✔ सही उत्तर: (b) Trueand पहले चलता है — True or (False) = True।
44

कौन-सा operator right-to-left associative है?

(a) +(b) *(c) **(d) //
✔ सही उत्तर: (c) **बाकी arithmetic operators left-to-right हैं।
45

10 - 4 + 2 का output —

(a) 4(b) 8(c) 16(d) 12
✔ सही उत्तर: (b) 8Left-to-right: (10-4)+2 = 8।
46

Value produce करने वाला combination कहलाता है —

(a) Statement(b) Expression(c) Keyword(d) Block
✔ सही उत्तर: (b) Expressionजैसे 2+3, a*b — इन्हें variable में रख सकते हैं।
47

x = 5 है —

(a) Expression(b) Assignment statement(c) Operator(d) Literal
✔ सही उत्तर: (b) Assignment statementयह action करता है, value produce नहीं।
48

a > 5 and b < 3 किस प्रकार का expression है?

(a) Arithmetic(b) String(c) Logical(d) Assignment
✔ सही उत्तर: (c) LogicalRelational expressions को and से जोड़ा गया है।
49

if/for जैसे header + indented block वाले statements कहलाते हैं —

(a) Simple(b) Compound(c) Empty(d) Nested
✔ सही उत्तर: (b) Compound statementsHeader में : और नीचे indented body।
50

print(5 > 3 > 1) का output —

(a) True(b) False(c) Error(d) 1
✔ सही उत्तर: (a) TrueChaining: 5>3 True और 3>1 True — दोनों true।

📝 B. 15 Theory Questions (Short Answers)

  1. Operator और Operand में अंतर बताइए।Operator वह symbol है जो operation करता है (+, ==, and); Operand वे values हैं जिन पर operation होता है। a + b में a, b operands और + operator।
  2. Unary, Binary व Ternary operators उदाहरण सहित लिखिए।Unary — 1 operand (-x, not flag, ~n); Binary — 2 operands (a+b, x>y); Ternary — condition वाला (largest = a if a>b else b)।
  3. Python के 7 प्रकार के operators के नाम लिखिए।Arithmetic, Relational (Comparison), Logical, Assignment, Bitwise, Membership (in/not in), Identity (is/is not)।
  4. / और // में अंतर उदाहरण सहित बताइए।/ true division — हमेशा float (10/3 = 3.333, 10/5 = 2.0); // floor division — नीचे की ओर rounded quotient (10//3 = 3, -10//3 = -4)।
  5. -10 // 3 का उत्तर -4 क्यों है, -3 क्यों नहीं?Floor यानी नीचे की ओर rounding — -3.33 के नीचे number line पर -4 आता है, -3 नहीं (यह ऊपर है)। इसीलिए negative floor division में हमेशा नीचे वाला integer।
  6. ** operator की associativity समझाइए।** अकेला right-to-left associative operator है — 2**3**2 में पहले दाईं ओर 3**2 = 9, फिर 2**9 = 512 (न कि (2**3)**2 = 64)।
  7. Comparison chaining क्या है?Python में कई comparisons एक साथ लिख सकते हैं — 10 < x < 20 यानी (10 < x) and (x < 20)। सभी comparisons true हों तभी result True।
  8. Short-circuit evaluation समझाइए।and में पहला operand falsy हो तो दूसरा evaluate नहीं होता (वही return); or में पहला truthy हो तो दूसरा skip। इससे speed बढ़ती है और x != 0 and 10/x जैसे patterns से errors से बचाव होता है।
  9. Python में falsy values कौन-सी हैं?0, 0.0, "" (empty string), None, False, खाली list []/tuple ()/dict {} — बाकी सब values truthy मानी जाती हैं (जैसे "0" string truthy है)।
  10. Augmented assignment operators क्या हैं? कोई 4 लिखिए।Operation + assignment के shortcuts — x += 5 (x = x+5), x -= 2, x *= 3, x //= 2, x **= 2। Python में ++/-- नहीं होते।
  11. ~ (bitwise NOT) का formula व उदाहरण लिखिए।~n = -(n+1) — इसलिए ~5 = -6, ~10 = -11, ~(-3) = 2। यह सभी bits उलट देता है (two's complement के कारण negative)।
  12. Left shift व Right shift की tricks बताइए।n << k = n × 2ᵏ (हर shift पर double); n >> k = n ÷ 2ᵏ (हर shift पर आधा, integer) — 5<<3 = 40, 80>>2 = 20।
  13. == और is में अंतर उदाहरण सहित बताइए।== values की equality (क्या बराबर हैं?); is object identity (क्या memory में एक ही object? id() same?)। a=[1,2]; b=[1,2] पर a==b True पर a is b False। None की जाँच x is None से।
  14. Operator precedence का पूरा क्रम लिखिए।() → ** → unary (~, +x, -x) → * / // % → + - → << >> → & → ^ → | → comparisons (==, >, in, is) → not → and → or।
  15. Expression और Statement में अंतर बताइए।Expression value produce करता है (2+3, a>b) — variable में रख सकते हैं; Statement action करता है (x=5, if, for, print) — ज़रूरी नहीं value दे। if/for = compound statements (header + indented block)।
Revision Tip: इस chapter के 5 पक्के traps — 10/5 = 2.0 (float!), -10//3 = -4, 2**3**2 = 512, "5 and 10" = 10, a is b vs a == b। ये पाँचों हर exam में किसी न किसी रूप में आते हैं!
FAQ

अक्सर पूछे जाने वाले प्रश्न

Python में कितने प्रकार के operators होते हैं?
7 मुख्य प्रकार — Arithmetic (+, -, *, /, //, %, **), Relational/Comparison (==, !=, >, <, >=, <=), Logical (and, or, not), Assignment (=, +=, -=...), Bitwise (&, |, ^, ~, <<, >>), Membership (in, not in) और Identity (is, is not)।
/ और // operator में क्या अंतर है?
/ (true division) हमेशा float result देता है — 10/3 = 3.333...; // (floor division) quotient को नीचे की ओर round करके देता है — 10//3 = 3। ध्यान दें: negative numbers पर -10//3 = -4 आता है (नीचे की ओर rounding), -3 नहीं।
== और is में क्या अंतर है?
== values की तुलना करता है (क्या दोनों की value बराबर है?); is object identity की तुलना करता है (क्या दोनों memory में एक ही object हैं? — id() same?)। दो अलग lists में same values हों तो == True पर is False देगा।
Short-circuit evaluation क्या है?
Logical operators में Python पूरा expression evaluate नहीं करता अगर answer पहले ही तय हो जाए — and में पहला operand False हो तो दूसरा check ही नहीं होता; or में पहला True हो तो दूसरा skip। इससे speed बढ़ती है और errors से बचाव होता है।
Python में operator precedence का सबसे ऊँचा और सबसे नीचा स्तर कौन-सा है?
सबसे ऊँची precedence Parentheses () की, फिर ** (exponent) — जो right-to-left associative है। सबसे नीची precedence assignment operators (=, +=) और फिर logical or की होती है। क्रम: () → ** → * / // % → + - → comparison → not → and → or।
Expression और Statement में क्या अंतर है?
Expression एक value produce करता है (2 + 3, a * b, x > 5) — इसे variable में रख सकते हैं। Statement एक पूरा instruction है जो कोई action करता है (x = 5, if, for, print()) — ज़रूरी नहीं कि value दे। हर expression statement बन सकता है, पर हर statement expression नहीं।

🎯 Chapter 4 पूरा हुआ! अब आगे बढ़ें

Chapter 5 में Sequence Data Types — Strings, Lists, Tuples, Dictionaries व Sets की पूरी दुनिया, methods व slicing के साथ।

Chapter 5 पढ़ें ➜