PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power) (पायथन अंकगणित: ट्रू डिवीजन (/), फ्लोर डिवीजन (//) और पावर (**)) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: Python provides seven core arithmetic operators (+, -, *, /, //, %, **) for numeric computation across int, float, and complex types. Unlike C or Java, Python 3 separates floating-point true division (/) from floor division (//) toward negative infinity and pairs // with modulo (%) via exact Euclidean floor identities.
अध्याय सार: पायथन int, float और complex डेटा प्रकारों पर गणना के लिए सात मुख्य अंकगणितीय ऑपरेटर्स (+, -, *, /, //, %, **) प्रदान करता है। C या Java के विपरीत, पायथन 3 में ट्रू डिवीजन (/) हमेशा फ्लोट परिणाम देता है, जबकि फ्लोर डिवीजन (//) ऋणात्मक अनंत की ओर राउंड करता है।
Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power): Detailed Notes & Architecture (पायथन अंकगणित: ट्रू डिवीजन (/), फ्लोर डिवीजन (//) और पावर (**))
1. Basic Arithmetic and Numeric Type Promotion (बुनियादी अंकगणित और न्यूमेरिक टाइप प्रमोशन)
[EN] Addition (+), subtraction (-), and multiplication (*) operate on int, float, complex, and even bool (since bool subclasses int with True == 1 and False == 0). When an int combines with a float, Python automatically promotes the result to float; combining with complex yields complex. Python integers have arbitrary precision, meaning integer multiplication or addition never suffers 32-bit or 64-bit overflow as in C/C++. Note that + and * are also overloaded for sequence concatenation and repetition, whereas - and / are strictly numeric.
[HI] जोड़ (+), घटाव (-) और गुणा (*) ऑपरेटर्स int, float, complex और यहाँ तक कि bool (जहाँ True == 1 और False == 0 होता है) पर कार्य करते हैं। जब एक int और float के बीच गणना होती है, तो पायथन परिणाम को स्वतः float में प्रमोट कर देता है; complex के साथ परिणाम complex बनता है। पायथन में पूर्णांकों (int) की सटीकता असीमित (arbitrary precision) होती है, इसलिए C/C++ की तरह इनमें 32-बिट या 64-बिट ओवरफ्लो नहीं होता। ध्यान दें कि + और * सीक्वेंस जोड़ने व दोहराने के लिए भी ओवरलोडेड हैं, लेकिन - और / केवल संख्याओं पर लागू होते हैं।
2. True Division (/) vs Floor Division (//) (ट्रू डिवीजन (/) बनाम फ्लोर डिवीजन (//))
[EN] In Python 3, the true division operator (/) always returns a float, even when both operands divide evenly (e.g., 8 / 2 produces 4.0, unlike Python 2 integer division). The floor division operator (//) divides two numbers and applies math.floor(), rounding down toward negative infinity rather than truncating toward zero. Consequently, 7 // 2 yields 3, whereas -7 // 2 yields -4 (because -3.5 floored toward negative infinity is -4). If either operand of // is a float, the result is a float (e.g., 7.0 // 2 gives 3.0), and complex numbers raise TypeError with //.
[HI] पायथन 3 में ट्रू डिवीजन (/) हमेशा float लौटाता है, भले ही भागफल पूरा-पूरा विभाजित हो जाए (जैसे 8 / 2 का मान 4.0 होगा, जबकि पायथन 2 में यह पूर्णांक देता था)। फ्लोर डिवीजन (//) भाग देने के बाद परिणाम को शून्य की ओर काटने (truncate) के बजाय ऋणात्मक अनंत की ओर नीचे राउंड (floor) करता है। इसी कारण 7 // 2 का परिणाम 3 आता है, जबकि -7 // 2 का परिणाम -4 होता है (क्योंकि -3.5 का फ्लोर मान -4 है)। यदि // के किसी भी ऑपरेंड का प्रकार float हो तो परिणाम float (जैसे 7.0 // 2 = 3.0) होता है, तथा complex संख्याओं पर // से TypeError आता है।
3. Modulo (%) Invariant, Negative Operands, and divmod() (मॉड्यूलो (%) नियम, ऋणात्मक ऑपरेंड और divmod())
[EN] Python enforces the invariant a == (a // b) * b + (a % b) for all real numbers where b != 0. Because // rounds toward negative infinity, the remainder a % b always takes the sign of the divisor b (for instance, -7 % 3 evaluates to 2 because (-3) * 3 + 2 == -7, whereas 7 % -3 gives -2). Attempting /, //, or % with a zero divisor (0 or 0.0) immediately raises ZeroDivisionError. The built-in function divmod(a, b) computes both quotient and remainder in one step and returns the tuple (a // b, a % b).
[HI] पायथन सभी वास्तविक संख्याओं (b != 0) के लिए समीकरण a == (a // b) * b + (a % b) का सख्ती से पालन करता है। चूंकि // ऋणात्मक अनंत की ओर झुकता है, इसलिए शेषफल (a % b) का चिह्न हमेशा भाजक b के चिह्न के समान होता है (जैसे -7 % 3 == 2 और 7 % -3 == -2)। भाजक शून्य (0 या 0.0) होने पर /, // और % तीनों ही ZeroDivisionError उत्पन्न करते हैं। अंतर्निहित फंक्शन divmod(a, b) एक ही गणना में भागफल और शेषफल दोनों निकालकर (a // b, a % b) टपल के रूप में लौटाता है।
4. Exponentiation (**), Precedence, and Right Associativity (घातांक (**), प्राथमिकता और राइट एसोसिएटिविटी)
[EN] The power operator (**) computes a raised to b and is the only binary arithmetic operator in Python that is right-associative: 2 ** 3 ** 2 evaluates as 2 ** (3 ** 2) = 512 rather than 64. In Python's grammar, ** binds tighter than unary negation on its left, so -3 ** 2 equals -(3 ** 2) = -9, whereas (-3) ** 2 equals 9 and 2 ** -2 equals 0.25. Among arithmetic operators, precedence goes: ** (highest), unary +/-, then (*, /, //, %) left-to-right, and finally (+, -) left-to-right. Additionally, 0 ** 0 evaluates to 1 in Python, and raising a negative number to a fractional power like (-4) ** 0.5 yields a complex number in Python 3.
[HI] पावर ऑपरेटर (**) घातांक की गणना करता है और पायथन का एकमात्र बाइनरी अंकगणितीय ऑपरेटर है जो राइट-एसोसिएटिव है: अर्थात 2 ** 3 ** 2 को 2 ** (3 ** 2) = 512 माना जाता है, न कि 64। पायथन में ** की प्राथमिकता बाईं ओर लगे यूनरी माइनस से अधिक होती है, इसलिए -3 ** 2 का मान -(3 ** 2) = -9 होता है, जबकि (-3) ** 2 का मान 9 और 2 ** -2 का मान 0.25 होता है। अंकगणितीय प्राथमिकता क्रम: ** (सर्वोच्च) > यूनरी +/- > (*, /, //, % बाएँ से दाएँ) > (+, - बाएँ से दाएँ)। साथ ही पायथन में 0 ** 0 का मान 1 होता है और ऋणात्मक आधार पर भिन्नात्मक घात से complex संख्या प्राप्त होती है।
Syntax, Formula & Technical Example (Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power))
print(10 / 4, 10 // 4) # 2.5 2
print(-7 // 2, -7 % 2) # -4 1
print(7.0 // 2, 7.5 % 2) # 3.0 1.5
print(2 ** 3 ** 2) # 512
print(-3 ** 2, (-3) ** 2) # -9 9
print(divmod(17, 5)) # (3, 2)
Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power) Quick Reference & Comparison Table
| Operator | Operation & Return Type | Key Exam Fact |
|---|---|---|
| / | True Division (always float) | 8 / 2 returns 4.0 in Python 3 |
| // | Floor Division (rounds to -inf) | -7 // 2 equals -4, not -3 |
| % | Modulo Remainder (sign of divisor) | Satisfies a == (a // b)*b + (a % b) |
| ** | Exponentiation (right-associative) | 2**3**2 == 512; -3**2 == -9 |
Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power) Top 20 Bilingual MCQs with Answers
Q1. What is the output of 10 / 2 in Python 3?
(पायथन 3 में 10 / 2 का आउटपुट क्या होगा?)
(A) 5
(B) TypeError
(C) 5.00
(D) 5.0
Correct Answer: (D)
[EN] The true division operator (/) always returns a float in Python 3, even for exact integer multiples.
[HI] पायथन 3 में ट्रू डिवीजन ऑपरेटर (/) हमेशा float मान लौटता है, चाहे भागफल पूर्णांक ही क्यों न हो।
Q2. What does the expression -11 // 4 evaluate to in Python?
(पायथन में व्यंजक -11 // 4 का मान क्या होगा?)
(A) -3
(B) -2
(C) -2.75
(D) 3
Correct Answer: (A)
[EN] Floor division rounds toward negative infinity: -11 / 4 is -2.75, and math.floor(-2.75) is -3.
[HI] फ्लोर डिवीजन ऋणात्मक अनंत की ओर राउंड करता है: -11 / 4 = -2.75 का फ्लोर मान -3 होता है।
Q3. What is the result of -7 % 3 in Python?
(पायथन में -7 % 3 का परिणाम क्या होता है?)
(A) 2
(B) 1
(C) -2
(D) -1
Correct Answer: (A)
[EN] Using a == (a // b) * b + (a % b), -7 // 3 is -3, so (-3) * 3 + 2 == -7; remainder takes the sign of divisor 3.
[HI] नियम a == (a // b) * b + (a % b) के अनुसार -7 // 3 = -3 होता है, अतः शेषफल 2 होगा (भाजक 3 के चिह्न सहित)।
Q4. What is the output of 2 ** 3 ** 2 in Python?
(पायथन में 2 ** 3 ** 2 का आउटपुट क्या होगा?)
(A) 256
(B) 64
(C) 36
(D) 512
Correct Answer: (D)
[EN] The ** operator is right-associative, so 2 ** 3 ** 2 evaluates as 2 ** (3 ** 2) = 2 ** 9 = 512.
[HI] ** ऑपरेटर राइट-एसोसिएटिव होता है, इसलिए यह 2 ** (3 ** 2) = 2 ** 9 = 512 के रूप में हल होता है।
Q5. What does -2 ** 4 evaluate to in Python?
(पायथन में -2 ** 4 का मान क्या होगा?)
(A) 8
(B) 16
(C) -16
(D) SyntaxError
Correct Answer: (C)
[EN] Exponentiation ** binds tighter than unary minus on its left, so -2 ** 4 parses as -(2 ** 4) = -16.
[HI] बाईं ओर के यूनरी माइनस की तुलना में ** की प्राथमिकता अधिक होती है, अतः -2 ** 4 = -(2 ** 4) = -16 होता है।
Q6. What is the data type of the result of 7.0 // 2?
(7.0 // 2 के परिणाम का डेटा टाइप क्या होगा?)
(A) decimal
(B) int
(C) float
(D) complex
Correct Answer: (C)
[EN] Whenever either operand of // is a float, Python returns a float (here 3.0).
[HI] जब // का कोई भी ऑपरेंड float होता है, तो पायथन परिणाम भी float (यहाँ 3.0) देता है।
Q7. Which built-in function returns both (a // b) and (a % b) as a tuple?
(कौन सा अंतर्निहित फंक्शन (a // b) और (a % b) दोनों को एक टपल में लौटाता है?)
(A) modf(a, b)
(B) fmod(a, b)
(C) quotient(a, b)
(D) divmod(a, b)
Correct Answer: (D)
[EN] divmod(a, b) returns the 2-tuple (a // b, a % b) in a single operation.
[HI] divmod(a, b) एक ही कॉल में (a // b, a % b) का टपल लौटाता है।
Q8. What happens when you evaluate (3 + 4j) // 2 in Python?
(पायथन में (3 + 4j) // 2 चलाने पर क्या होता है?)
(A) Returns 1.5
(B) TypeError is raised
(C) Returns (1 + 2j)
(D) ZeroDivisionError is raised
Correct Answer: (B)
[EN] Floor division (//) and modulo (%) are not defined for complex numbers in Python 3 and raise TypeError.
[HI] पायथन 3 में complex संख्याओं पर // और % परिभाषित नहीं हैं और इनसे TypeError आता है।
Q9. What is the output of 7 % -3 in Python?
(पायथन में 7 % -3 का आउटपुट क्या होगा?)
(A) 1
(B) -2
(C) 2
(D) -1
Correct Answer: (B)
[EN] 7 // -3 is -3, and (-3) * (-3) + (-2) = 7; the modulo result always takes the sign of the divisor (-3).
[HI] 7 // -3 का मान -3 है, और (-3)*(-3) + (-2) = 7; अतः शेषफल भाजक (-3) के चिह्न के साथ -2 आएगा।
Q10. What is the result of True + True * 3 in Python?
(पायथन में True + True * 3 का परिणाम क्या है?)
(A) 6
(B) True
(C) TypeError
(D) 4
Correct Answer: (D)
[EN] bool is a subclass of int (True == 1), and * has higher precedence than +, so 1 + (1 * 3) = 4.
[HI] bool, int की सबक्लास है (True == 1), और * की प्राथमिकता + से अधिक है, इसलिए 1 + (1 * 3) = 4।
Q11. What does 0 ** 0 evaluate to in Python 3?
(पायथन 3 में 0 ** 0 का मान क्या होता है?)
(A) 0
(B) 1
(C) nan
(D) ZeroDivisionError
Correct Answer: (B)
[EN] By Python numeric convention (matching pow(0, 0)), 0 ** 0 evaluates to 1.
[HI] पायथन में गणितीय नियम (pow(0, 0) के समान) के तहत 0 ** 0 का मान 1 होता है।
Q12. What is the value of 15 - 3 * 2 ** 2 // 4 + 1?
(व्यंजक 15 - 3 * 2 ** 2 // 4 + 1 का मान क्या होगा?)
(A) 13
(B) 10
(C) 13.0
(D) 1
Correct Answer: (A)
[EN] Order: 2**2 = 4; then left-to-right 3 * 4 = 12, 12 // 4 = 3; finally 15 - 3 + 1 = 13.
[HI] क्रम: 2**2 = 4; फिर बाएँ से दाएँ 3*4 = 12, 12//4 = 3; अंत में 15 - 3 + 1 = 13।
Q13. Which exception is raised by 5 % 0.0?
(5 % 0.0 से कौन सा अपवाद (exception) उत्पन्न होता है?)
(A) FloatingPointError
(B) ValueError
(C) ZeroDivisionError
(D) ArithmeticError only without ZeroDivisionError
Correct Answer: (C)
[EN] Dividing or taking modulo by integer 0 or float 0.0 raises ZeroDivisionError.
[HI] पूर्णांक 0 या फ्लोट 0.0 से भाग या मॉड्यूलो करने पर ZeroDivisionError आता है।
Q14. What does 7.5 % 2.0 return?
(7.5 % 2.0 क्या मान लौटाता है?)
(A) TypeError
(B) 1.5
(C) 1
(D) 3.0
Correct Answer: (B)
[EN] Modulo works on floats as well: 7.5 // 2.0 = 3.0 and 7.5 - 3.0 * 2.0 = 1.5.
[HI] मॉड्यूलो ऑपरेटर float पर भी काम करता है: 7.5 // 2.0 = 3.0 तथा शेषफल 1.5।
Q15. What is the result of 2 ** -2 in Python?
(पायथन में 2 ** -2 का परिणाम क्या है?)
(A) -4
(B) 0.25
(C) 0
(D) 0.5
Correct Answer: (B)
[EN] Unary minus on the right side of ** binds first: 2 ** (-2) = 1 / 4 = 0.25 (float).
[HI] ** के दाईं ओर लगा यूनरी माइनस पहले हल होता है: 2 ** (-2) = 1/4 = 0.25।
Q16. Which of the following statements about Python arithmetic operators is NOT true?
(पायथन अंकगणितीय ऑपरेटर्स के बारे में निम्नलिखित में से कौन सा कथन सत्य नहीं है?)
(A) The / operator always produces a float result in Python 3
(B) All binary arithmetic operators in Python are left-associative
(C) The ** operator has higher precedence than * and //
(D) Python integers support arbitrary precision without fixed 64-bit overflow
Correct Answer: (B)
[EN] While +, -, *, /, //, and % are left-associative, the exponentiation operator ** is right-associative.
[HI] जहाँ +, -, *, /, // और % लेफ्ट-एसोसिएटिव हैं, वहीं घातांक ऑपरेटर ** राइट-एसोसिएटिव होता है।
Q17. Within Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power), which operator directly maps to: "True Division (always float)"?
(Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power) में कौन सा Operator सीधे "True Division (always float)" से संबंधित है?)
(A) %
(B) **
(C) /
(D) //
Correct Answer: (C)
[EN] In Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power), '/' handles 'True Division (always float)' (8 / 2 returns 4.0 in Python 3).
[HI] Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power) में '/' का कार्य/विवरण 'True Division (always float)' (8 / 2 returns 4.0 in Python 3) है।
Q18. Which option accurately describes '//' in Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power)?
(Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power) के संदर्भ में '//' की सही विशेषता कौन सी है?)
(A) True Division (always float)
(B) Floor Division (rounds to -inf)
(C) Modulo Remainder (sign of divisor)
(D) Exponentiation (right-associative)
Correct Answer: (B)
[EN] '//' provides 'Floor Division (rounds to -inf)' — key point: -7 // 2 equals -4, not -3.
[HI] '//' का मुख्य विवरण 'Floor Division (rounds to -inf)' है (-7 // 2 equals -4, not -3)।
Q19. In Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power), identify the correct parameter for the specification: "Modulo Remainder (sign of divisor)".
(Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power) में "Modulo Remainder (sign of divisor)" विवरण किस विकल्प के लिए सही है?)
(A) //
(B) %
(C) **
(D) /
Correct Answer: (B)
[EN] '%' corresponds to 'Modulo Remainder (sign of divisor)' (Satisfies a == (a // b)*b + (a % b)).
[HI] '%' का संबंध 'Modulo Remainder (sign of divisor)' (Satisfies a == (a // b)*b + (a % b)) से है।
Q20. Considering Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power), what key behavior defines '**'?
(Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power) में '**' की मुख्य भूमिका या मान क्या है?)
(A) Exponentiation (right-associative)
(B) Floor Division (rounds to -inf)
(C) Modulo Remainder (sign of divisor)
(D) True Division (always float)
Correct Answer: (A)
[EN] '**' represents 'Exponentiation (right-associative)' (2**3**2 == 512; -3**2 == -9).
[HI] '**' का अर्थ/मान 'Exponentiation (right-associative)' है (2**3**2 == 512; -3**2 == -9)।
Python Arithmetic Operators: +, -, *, /, // (Floor), % (Mod), ** (Power) — Exam FAQs
Q1: Why does -7 // 2 return -4 instead of -3 in Python?
पायथन में -7 // 2 का मान -3 के बजाय -4 क्यों आता है?
[EN] Because Python's // performs floor division (rounding toward negative infinity) rather than C-style truncation toward zero. Since -7 / 2 = -3.5, the largest integer less than or equal to -3.5 is -4.
[HI] क्योंकि पायथन का // ऑपरेटर C भाषा की तरह शून्य की ओर ट्रंकेट करने के बजाय ऋणात्मक अनंत की ओर फ्लोर राउंडिंग करता है; -3.5 से छोटा निकटतम पूर्णांक -4 है।
Q2: How do I get an integer quotient with / in Python 3?
पायथन 3 में पूर्णांक भागफल प्राप्त करने के लिए क्या उपयोग करें?
[EN] Use the floor division operator // (e.g., 10 // 2 returns int 5) instead of /, because / always returns a float (5.0) in Python 3.
[HI] पायथन 3 में / हमेशा float (5.0) लौटाता है, इसलिए पूर्णांक भागफल पाने के लिए फ्लोर डिवीजन ऑपरेटर // (जैसे 10 // 2 = 5) का उपयोग करें।
Q3: Why does -3 ** 2 give -9 instead of 9?
-3 ** 2 का उत्तर 9 के बजाय -9 क्यों आता है?
[EN] In Python's operator precedence table, ** binds tighter than the unary negation operator on its left, so -3 ** 2 is parsed as -(3 ** 2) = -9. Use parentheses (-3) ** 2 to square -3.
[HI] ऑपरेटर प्राथमिकता में ** बाईं ओर के यूनरी माइनस से अधिक मजबूत होता है, इसलिए यह -(3 ** 2) = -9 के रूप में हल होता है। -3 का वर्ग करने के लिए (-3) ** 2 लिखें।
Post a Comment
Post a Comment