⚡ Python में Operators क्या होते हैं? Arithmetic, Logical, Comparison [Hindi Guide – 2025 Updated]
Table of Contents
TogglePython में Operators वो symbols या keywords होते हैं जिनका इस्तेमाल हम values और variables पर operations करने के लिए करते हैं। इस गाइड में हम Python Operators in Hindi को आसान भाषा और examples के साथ समझेंगे, जिसमें Arithmetic, Logical और Comparison Operators शामिल हैं।
➕ Arithmetic Operators
गणितीय operations जैसे जोड़, घटाना, गुणा, भाग आदि करने के लिए इस्तेमाल होते हैं।
Example: a + b
, a - b
🔍 Logical Operators
Conditions को combine या invert करने के लिए इस्तेमाल होते हैं।
Example: a and b
, a or b
, not a
⚖️ Comparison Operators
दो values की तुलना करने के लिए इस्तेमाल होते हैं।
Example: a == b
, a != b
, a > b
📚 Python Operators Cheat Sheet (in Hindi) — Examples सहित
इस सेक्शन में हम python operators in hindi को एक नजर में समझेंगे—Arithmetic, Assignment, Comparison, Logical, Bitwise, Membership और Identity operators—साथ में छोटे-छोटे examples ताकि learning तेज़ रहे।
Category | Operators | Meaning | Quick Example |
---|---|---|---|
Arithmetic | + , - , * , / , // , % , ** |
जोड़, घटाना, गुणा, भाग, floor-division, remainder, power | 7//3 → 2 , 2**3 → 8 |
Assignment | = , += , -= , *= , /= , //= , %= , **= , &= , |= , ^= , >>= , <<= |
मान असाइन या update करना | x = 5; x += 2 → 7 |
Comparison | == , != , > , < , >= , <= |
दो values की तुलना | 3 != 4 → True |
Logical | and , or , not |
conditions combine/invert | (5>3) and (2<1) → False |
Bitwise | & , | , ^ , ~ , << , >> |
bits पर operations | 5 & 3 → 1 , 5 << 1 → 10 |
Membership | in , not in |
collection में सदस्यता | 'a' in 'data' → True |
Identity | is , is not |
same object identity? | x is None , a is b |
Precedence | () , ** , *, / , // , % , + , - , ... | कौन सा पहले चलेगा | 2 + 3 * 4 → 14 |
a, b = 7, 3
print(a + b, a - b, a * b) # 10 4 21
print(a / b) # 2.333...
print(a // b, a % b) # 2 1
print(a ** b) # 343
x, y = 10, 20
print(x == y, x != y, x < y, x >= 5) # False True True True
is_valid = (x < y) and (y < 100)
print(is_valid) # True
print(not (x > y)) # True
name = "Vista"
print("s" in name, "x" not in name) # True True
a = None
print(a is None) # Identity check
b = [1,2,3]; c = b
print(b is c) # True (same object)
x, y = 5, 3 # 5:0101, 3:0011
print(x & y) # 1
print(x | y) # 7
print(x ^ y) # 6
print(~x) # -6 (two's complement)
print(x << 1) # 10
print(x >> 1) # 2
**
, फिर */%
, फिर +-
🧪 Logical: short-circuit evaluation
🔍 Identity vs Equality: is
vs ==
🏅 10 Practice Problems — Python Operators (in Hindi)
नीचे दिए गए प्रश्नों से python operators in hindi में आपकी पकड़ मजबूत होगी। हर प्रश्न के लिए Hint और Solution मौजूद है। कोड ब्लॉक्स कॉपी-बटन के साथ हैं।
Q1. Discount Price
MRP और discount% देकर final price निकालें (2 दशमलव तक)।
💡 Hint
price × (1 – d/100); round()
✅ Solution
mrp = 999
disc = 20
final_price = round(mrp * (1 - disc/100), 2)
print(final_price) # 799.2
Q2. Operator Precedence
Expression 2 + 3 * 4 ** 2
का परिणाम बताएं।
💡 Hint
** > * > +
✅ Solution
print(2 + 3 * 4 ** 2) # 2 + 3 * 16 = 50
Q3. Wallet Updates
wallet = 1000; ₹250 जोड़ें, फिर 10% tax घटाएँ (compound assignment से)।
💡 Hint
+= और -= के साथ 10% = ×0.10
✅ Solution
wallet = 1000
wallet += 250
wallet -= wallet * 0.10
print(round(wallet, 2)) # 1125.0
Q4. Comparison Chain
जांचें कि score
0 और 100 के बीच है (inclusive)।
💡 Hint
0 ≤ score ≤ 100 chaining
✅ Solution
score = 86
print(0 <= score <= 100) # True
Q5. Login Check
email और password non-empty हों तो “OK” प्रिंट करें (short-circuit use)।
💡 Hint
if email and password:
✅ Solution
email, password = "a@b.com", "secret"
if email and password:
print("OK")
else:
print("Invalid")
Q6. Find Vowel
string में कोई vowel मौजूद है या नहीं?
💡 Hint
any(ch in 'aeiou')
✅ Solution
s = "Vista"
print(any(ch.lower() in "aeiou" for ch in s)) # True
Q7. Identity vs Equality
दो lists equal हों पर same object न हों — test करें।
💡 Hint
== vs is
✅ Solution
a = [1,2,3]
b = [1,2,3]
print(a == b) # True (values equal)
print(a is b) # False (different objects)
Q8. Even/Odd (Bitwise)
बिना % के जाँचें कि n even है या odd।
💡 Hint
n & 1
✅ Solution
n = 42
print("Even" if (n & 1) == 0 else "Odd") # Even
Q9. Pagination Calc
items=73, per_page=10 → total pages? (floor/ceil logic)
💡 Hint
(n + k - 1)//k
✅ Solution
items, per_page = 73, 10
pages = (items + per_page - 1) // per_page
print(pages) # 8
Q10. Filter Emails
list में से valid emails (जिनमें '@' और '.') हों।
💡 Hint
'@' in s and '.' in s
✅ Solution
emails = ["a@b.com", "foo", "x@y", "c@d.org"]
valid = [e for e in emails if ("@" in e and "." in e)]
print(valid) # ['a@b.com', 'c@d.org']