नीचे दिए गए प्रश्नों से python operators in hindi में आपकी पकड़ मजबूत होगी। हर प्रश्न के लिए Hint और Solution मौजूद है। कोड ब्लॉक्स कॉपी-बटन के साथ हैं।
MRP और discount% देकर final price निकालें (2 दशमलव तक)।
price × (1 – d/100); round()
mrp = 999
disc = 20
final_price = round(mrp * (1 - disc/100), 2)
print(final_price) # 799.2
Expression 2 + 3 * 4 ** 2 का परिणाम बताएं।
** > * > +
print(2 + 3 * 4 ** 2) # 2 + 3 * 16 = 50
wallet = 1000; ₹250 जोड़ें, फिर 10% tax घटाएँ (compound assignment से)।
+= और -= के साथ 10% = ×0.10
wallet = 1000
wallet += 250
wallet -= wallet * 0.10
print(round(wallet, 2)) # 1125.0
जांचें कि score 0 और 100 के बीच है (inclusive)।
0 ≤ score ≤ 100 chaining
score = 86
print(0 <= score <= 100) # True
email और password non-empty हों तो “OK” प्रिंट करें (short-circuit use)।
if email and password:
email, password = "a@b.com", "secret"
if email and password:
print("OK")
else:
print("Invalid")
string में कोई vowel मौजूद है या नहीं?
any(ch in 'aeiou')
s = "Vista"
print(any(ch.lower() in "aeiou" for ch in s)) # True
दो lists equal हों पर same object न हों — test करें।
== vs is
a = [1,2,3]
b = [1,2,3]
print(a == b) # True (values equal)
print(a is b) # False (different objects)
बिना % के जाँचें कि n even है या odd।
n & 1
n = 42
print("Even" if (n & 1) == 0 else "Odd") # Even
items=73, per_page=10 → total pages? (floor/ceil logic)
(n + k - 1)//k
items, per_page = 73, 10
pages = (items + per_page - 1) // per_page
print(pages) # 8
list में से valid emails (जिनमें '@' और '.') हों।
'@' in s and '.' in s
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']