Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError Notes in Hindi & English : प्रमुख एक्सेप्शन्स: ZeroDivisionError, ValueError, KeyError और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError (प्रमुख एक्सेप्शन्स: ZeroDivisionError, ValueError, KeyError) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: ZeroDivisionError, ValueError, KeyError, and IndexError are Python's four most frequently encountered runtime exceptions in everyday code and competitive exams. Understanding their parent hierarchy (ArithmeticError, LookupError), exact trigger boundaries, and EAFP/get() safeguards eliminates runtime crashes.

अध्याय सार: ZeroDivisionError, ValueError, KeyError और IndexError दैनिक प्रोग्रामिंग और प्रतियोगी परीक्षाओं में सबसे अधिक आने वाले चार प्रमुख बिल्ट-इन एक्सेप्शन्स हैं। इनकी पैरेंट क्लास (ArithmeticError, LookupError), सटीक कारण और बचाव के तरीके समझने से रनटाइम क्रैश से बचा जा सकता है।

Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError: Detailed Notes & Architecture (प्रमुख एक्सेप्शन्स: ZeroDivisionError, ValueError, KeyError)

1. ZeroDivisionError and the ArithmeticError Hierarchy (ZeroDivisionError और ArithmeticError श्रेणी)

[EN] `ZeroDivisionError` inherits from `ArithmeticError` (alongside `OverflowError` and `FloatingPointError`) and triggers whenever the divisor of `/`, `//`, `%`, or `divmod()` evaluates to `0` or `0.0`. Unlike JavaScript or C/C++ IEEE 754 floats where `1.0 / 0.0` evaluates to `Infinity` and `0.0 / 0.0` yields `NaN`, Python strictly raises `ZeroDivisionError` for both integer and floating-point zero divisors (e.g., `5.0 / 0.0`, `10 % 0`, `10 // 0.0`). Note that multiplying by `0` or dividing `0 / 5` is completely valid (`0.0`). Also beware that `0 ** -1` (raising zero to a negative power) triggers `ZeroDivisionError` because it equals `1 / 0`.

[HI] `ZeroDivisionError`, `ArithmeticError` क्लास का उपवर्ग है और तब आता है जब `/`, `//`, `%` या `divmod()` में भाजक (divisor) `0` या `0.0` हो। C++ या JavaScript के विपरीत जहाँ `1.0 / 0.0` का मान `Infinity` होता है, पायथन में फ्लोट `5.0 / 0.0` या `10 % 0` पर भी सख्ती से `ZeroDivisionError` आता है। ध्यान दें कि `0 / 5` करने पर `0.0` मिलता है (कोई त्रुटि नहीं), जबकि `0 ** -1` करने पर भी `1/0` होने के कारण `ZeroDivisionError` उत्पन्न होता है।

2. ValueError vs TypeError: Right Type, Invalid Content (ValueError बनाम TypeError: सही टाइप पर गलत मान)

[EN] `ValueError` inherits directly from `Exception` and occurs when an operation or function receives an object of the *correct data type* but an *inappropriate value*. Classic exam examples include `int('abc')`, `int('3.14')` (string containing a decimal dot rather than pure integer digits), `math.sqrt(-4)`, `chr(-1)`, `[1, 2].remove(9)`, and sequence unpacking mismatches like `a, b = [1, 2, 3]`. By contrast, `TypeError` indicates the *wrong data type* altogether—such as `int(None)`, `len(42)`, or `'age: ' + 25`. Mastering this distinction ('right type, bad content' = `ValueError`; 'incompatible type' = `TypeError`) solves numerous tricky exam questions.

[HI] `ValueError` सीधे `Exception` से इनहेरिट करता है और तब उत्पन्न होता है जब किसी फंक्शन को *सही डेटा टाइप* का ऑब्जेक्ट तो मिले, लेकिन उसका *मान अमान्य* हो। प्रमुख उदाहरण हैं: `int('abc')`, `int('3.14')`, `math.sqrt(-4)`, `[1, 2].remove(9)` और अनपैकिंग बेमेल `a, b = [1, 2, 3]`। इसके विपरीत `TypeError` तब आता है जब *डेटा टाइप ही गलत* हो, जैसे `int(None)`, `len(42)` या `'abc' + 5`। परीक्षा में यह अंतर ('सही टाइप, गलत मान' = `ValueError`; 'गलत टाइप' = `TypeError`) अत्यंत महत्वपूर्ण है।

3. KeyError: Missing Mapping Keys and Dictionary Safeguards (KeyError: अनुपस्थित डिक्शनरी कुंजी और सुरक्षित विकल्प)

[EN] `KeyError` inherits from `LookupError` and is raised when a mapping (dictionary) lookup fails to find the requested key, such as `d['missing']`, `del d['missing']`, or `{}.pop('x')` / `{}.popitem()`. Interestingly, `{1, 2}.remove(9)` on a Python `set` also raises `KeyError`, whereas `[1, 2].remove(9)` on a `list` raises `ValueError`! Safe alternatives avoid `KeyError` cleanly: `d.get('missing', default)` returns `None` or the fallback value, `d.pop('missing', None)` removes safely without crashing, and `collections.defaultdict` auto-creates missing keys. When using EAFP ('Easier to Ask for Forgiveness than Permission'), `try: val = d[k] except KeyError:` avoids a double key hash lookup.

[HI] `KeyError`, `LookupError` का उपवर्ग है और तब आता है जब डिक्शनरी में `d['missing']` खोजने, `del d['missing']` या खाली `{}.popitem()` करने पर कुंजी मौजूद न हो। परीक्षा का विशेष तथ्य: सेट पर `{1, 2}.remove(9)` करने से `KeyError` आता है, जबकि लिस्ट पर `[1, 2].remove(9)` करने से `ValueError` आता है! `KeyError` से बचने के लिए `d.get(key, default)`, `d.pop(key, None)`, `key in d` जांच या `collections.defaultdict` का उपयोग किया जाता है।

4. IndexError and the Shared LookupError Parent (IndexError और साझा LookupError पैरेंट क्लास)

[EN] `IndexError` also inherits from `LookupError` and occurs when indexing a sequence (`list`, `tuple`, `str`) with an integer position outside `[-len(seq), len(seq) - 1]`, or calling `[].pop()` on an empty list. Importantly, sequence SLICING never raises `IndexError`: `[10, 20][5:10]` simply returns `[]` and `'hi'[10:20]` returns `''` because Python clamps slice boundaries safely. Because both `KeyError` and `IndexError` share the parent class `LookupError`, writing `except LookupError:` catches either exception in polymorphic lookup code. Similarly, checking `if 0 <= idx < len(seq):` (LBYL) or catching `IndexError` (EAFP) prevents sequence boundary crashes.

[HI] `IndexError` भी `LookupError` का उपवर्ग है और तब आता है जब लिस्ट, टपल या स्ट्रिंग में वैध इंडेक्स सीमा से बाहर का इंडेक्स मांगा जाए (या खाली `[].pop()` कॉल हो)। महत्वपूर्ण अपवाद: स्लाइसिंग में कभी `IndexError` नहीं आता—`[10, 20][5:10]` सुरक्षित रूप से `[]` और `'hi'[10:20]` खाली स्ट्रिंग `''` लौटाता है। चूंकि `KeyError` और `IndexError` दोनों `LookupError` के चाइल्ड हैं, इसलिए `except LookupError:` लिखकर दोनों को एक साथ पकड़ा जा सकता है।

Syntax, Formula & Technical Example (Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError)

samples = [lambda: 10 / 0, lambda: int("3.14"),
           lambda: {"a": 1}["b"], lambda: [10, 20][5]]
for fn in samples:
    try:
        fn()
    except (ArithmeticError, ValueError, LookupError) as err:
        print(type(err).__name__, "->", err)
print("Safe slice & get:", [10, 20][5:9], {"a": 1}.get("b", 0))

Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError Quick Reference & Comparison Table

Built-in ExceptionParent Class & Primary TriggerKey Exam Fact
ZeroDivisionErrorArithmeticError; divisor 0 in /, //, %Triggered even by float 5.0 / 0.0 and 0 ** -1
ValueErrorException; right type, invalid contente.g. int('3.14'), math.sqrt(-1), [1].remove(9)
KeyErrorLookupError; missing dict key / set.removeAvoid via dict.get(k, default) or defaultdict
IndexErrorLookupError; out-of-range sequence indexSlicing like [1, 2][5:9] returns [] without error

Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError Top 20 Bilingual MCQs with Answers

Q1. Which exception is raised by evaluating `int('3.14')` in Python?

(पायथन में `int('3.14')` चलाने पर कौन-सा एक्सेप्शन उत्पन्न होता है?)

(A) ZeroDivisionError

(B) ValueError

(C) TypeError

(D) SyntaxError

Correct Answer: (B)

[EN] `int()` accepts a `str`, so the type is right, but `'3.14'` is not a valid base-10 integer literal, raising `ValueError`.

[HI] `int()` स्ट्रिंग स्वीकार करता है (सही टाइप), लेकिन `'3.14'` पूर्णांक मान नहीं है, इसलिए `ValueError` आता है।

Q2. Which exception is raised by evaluating `int(None)` or `'Age: ' + 25`?

(`int(None)` या `'Age: ' + 25` चलाने पर कौन-सा एक्सेप्शन आता है?)

(A) NameError

(B) TypeError

(C) ValueError

(D) KeyError

Correct Answer: (B)

[EN] `None` and `int` are incompatible data types for `int()` and string `+`, raising `TypeError` rather than `ValueError`.

[HI] यहां डेटा टाइप ही अनुपयुक्त है (`None` या स्ट्रिंग+इंटीजर), इसलिए `ValueError` नहीं बल्कि `TypeError` आता है।

Q3. What is the immediate common parent class of both `KeyError` and `IndexError`?

(`KeyError` और `IndexError` दोनों की तत्काल साझा पैरेंट क्लास कौन-सी है?)

(A) ValueError

(B) KeyErrorBase

(C) ArithmeticError

(D) LookupError

Correct Answer: (D)

[EN] Both mapping key lookup failures (`KeyError`) and sequence index failures (`IndexError`) inherit from `LookupError`.

[HI] `KeyError` और `IndexError` दोनों ही `LookupError` बेस क्लास से इनहेरिट करते हैं।

Q4. What is the immediate parent class of `ZeroDivisionError`?

(`ZeroDivisionError` की तत्काल पैरेंट क्लास कौन-सी है?)

(A) LookupError

(B) MathError

(C) ValueError

(D) ArithmeticError

Correct Answer: (D)

[EN] `ArithmeticError` is the parent class of `ZeroDivisionError`, `OverflowError`, and `FloatingPointError`.

[HI] `ZeroDivisionError`, `OverflowError` और `FloatingPointError` तीनों `ArithmeticError` से इनहेरिट करते हैं।

Q5. What does Python produce when evaluating `10.0 / 0.0`?

(पायथन में `10.0 / 0.0` का मूल्यांकन करने पर क्या प्राप्त होता है?)

(A) Returns float('inf')

(B) Returns 0.0

(C) Returns float('nan')

(D) Raises ZeroDivisionError

Correct Answer: (D)

[EN] Unlike C/JS IEEE 754 division, Python raises `ZeroDivisionError` for both integer and floating-point zero divisors.

[HI] अन्य कई भाषाओं के विपरीत, पायथन में फ्लोट `10.0 / 0.0` पर भी `ZeroDivisionError` उत्पन्न होता है।

Q6. Which expression does NOT raise `ZeroDivisionError`?

(निम्न में से किस एक्सप्रेशन से `ZeroDivisionError` उत्पन्न नहीं होगा?)

(A) 5 % 0

(B) 5 // 0

(C) 0 ** -2

(D) 0 / 5

Correct Answer: (D)

[EN] Zero divided by a non-zero number (`0 / 5`) cleanly returns `0.0`, whereas `% 0`, `// 0`, and `0 ** -2` (`1/0`) all fail.

[HI] `0 / 5` का परिणाम `0.0` होता है (कोई त्रुटि नहीं), जबकि `% 0`, `// 0` और `0 ** -2` सभी `ZeroDivisionError` देते हैं।

Q7. What does `[10, 20, 30][5:10]` evaluate to in Python?

(पायथन में `[10, 20, 30][5:10]` का क्या परिणाम होगा?)

(A) [30]

(B) [] (empty list, no exception)

(C) IndexError: list index out of range

(D) None

Correct Answer: (B)

[EN] List and string slicing clamps out-of-range bounds gracefully and returns an empty slice instead of raising `IndexError`.

[HI] स्लाइसिंग में सीमा से बाहर के इंडेक्स देने पर `IndexError` नहीं आता, बल्कि खाली लिस्ट `[]` लौटती है।

Q8. What does `[10, 20, 30][-4]` raise?

(`[10, 20, 30][-4]` चलाने पर क्या होगा?)

(A) KeyError

(B) IndexError

(C) 10

(D) ValueError

Correct Answer: (B)

[EN] Valid negative indices for a 3-element list are `-1`, `-2`, and `-3`; `-4` is out of range and raises `IndexError`.

[HI] 3 तत्वों वाली लिस्ट के वैध ऋणात्मक इंडेक्स `-1, -2, -3` हैं; `-4` सीमा से बाहर होने से `IndexError` देता है।

Q9. Which dictionary expression safely returns `0` instead of raising `KeyError` when `'score'` is absent?

(जब डिक्शनरी `d` में `'score'` कुंजी न हो, तो `KeyError` के बिना सुरक्षित रूप से `0` लौटाने वाला एक्सप्रेशन कौन-सा है?)

(A) d.get('score', 0)

(B) d['score']

(C) d.pop('score')

(D) del d['score']

Correct Answer: (A)

[EN] `dict.get(key, default)` returns `default` (or `None` if omitted) whenever `key` is missing.

[HI] `d.get('score', 0)` कुंजी न मिलने पर त्रुटि के बिना डिफ़ॉल्ट मान `0` लौटाता है।

Q10. What exception is raised by tuple unpacking `a, b = [1, 2, 3]`?

(`a, b = [1, 2, 3]` टपल अनपैकिंग करने पर कौन-सा एक्सेप्शन उत्पन्न होता है?)

(A) KeyError

(B) TypeError

(C) IndexError

(D) ValueError: too many values to unpack

Correct Answer: (D)

[EN] Passing a sequence of the right iterable type with mismatched item count triggers `ValueError`.

[HI] अनपैकिंग में तत्वों की संख्या कम या ज्यादा होने पर `ValueError` उत्पन्न होता है।

Q11. What exceptions do `[1, 2].remove(9)` (on a list) and `{1, 2}.remove(9)` (on a set) raise respectively?

(`[1, 2].remove(9)` (लिस्ट पर) और `{1, 2}.remove(9)` (सेट पर) क्रमशः कौन-से एक्सेप्शन देते हैं?)

(A) IndexError for list, KeyError for set

(B) ValueError for both

(C) KeyError for list, ValueError for set

(D) ValueError for list, KeyError for set

Correct Answer: (D)

[EN] `list.remove()` checks by value and raises `ValueError`; `set.remove()` acts like a hash key lookup and raises `KeyError`.

[HI] लिस्ट का `remove()` मान न मिलने पर `ValueError` देता है, जबकि सेट हैश-की आधारित होने से `KeyError` देता है।

Q12. What exception occurs when calling `[].pop()` on an empty list vs `{}.popitem()` on an empty dictionary?

(खाली लिस्ट पर `[].pop()` और खाली डिक्शनरी पर `{}.popitem()` कॉल करने पर क्रमशः कौन-से एक्सेप्शन आते हैं?)

(A) IndexError for [].pop(), KeyError for {}.popitem()

(B) ValueError for [].pop(), IndexError for {}.popitem()

(C) KeyError for both

(D) IndexError for both

Correct Answer: (A)

[EN] Popping from an empty sequence raises `IndexError`; popping an item from an empty dict raises `KeyError`.

[HI] खाली लिस्ट से `pop()` करने पर `IndexError` और खाली डिक्शनरी से `popitem()` करने पर `KeyError` आता है।

Q13. Which exception is raised by `'hello'.index('z')` when `'z'` is not in the string?

(जब `'hello'` में `'z'` मौजूद न हो, तो `'hello'.index('z')` कौन-सा एक्सेप्शन देता है?)

(A) Returns -1

(B) ValueError (substring not found)

(C) IndexError

(D) KeyError

Correct Answer: (B)

[EN] `str.find('z')` returns `-1`, whereas `str.index('z')` (and `list.index()`) raises `ValueError`.

[HI] `str.find('z')` तो `-1` लौटाता है, लेकिन `str.index('z')` न मिलने पर `ValueError` देता है।

Q14. If a handler is written as `except LookupError:`, which pair of errors will it catch?

(यदि `except LookupError:` लिखा जाए, तो यह किन दो त्रुटियों को पकड़ लेगा?)

(A) Both KeyError and IndexError

(B) Both KeyError and ValueError

(C) Both ZeroDivisionError and OverflowError

(D) Both ValueError and TypeError

Correct Answer: (A)

[EN] Since both `KeyError` and `IndexError` inherit from `LookupError`, catching `LookupError` handles both.

[HI] `KeyError` और `IndexError` दोनों `LookupError` के चाइल्ड हैं, इसलिए यह दोनों को पकड़ लेता है।

Q15. What exception does `math.factorial(-3)` or `chr(1114112)` raise?

(`math.factorial(-3)` या `chr(1114112)` कॉल करने पर कौन-सा एक्सेप्शन उत्पन्न होता है?)

(A) ArithmeticError

(B) OverflowError

(C) TypeError

(D) ValueError

Correct Answer: (D)

[EN] Both receive valid `int` arguments outside their mathematically/Unicode defined value domain, triggering `ValueError`.

[HI] दोनों को सही `int` टाइप मिला है पर मान वैध सीमा से बाहर है, इसलिए `ValueError` आता है।

Q16. Which statement is NOT true about Python's built-in exceptions?

(पायथन के बिल्ट-इन एक्सेप्शन्स के बारे में निम्न में से कौन-सा कथन सत्य नहीं है?)

(A) ZeroDivisionError is a subclass of ArithmeticError

(B) int('abc') raises ValueError while int(None) raises TypeError

(C) List slicing like [1, 2][5:10] raises IndexError just like indexing [1, 2][5]

(D) KeyError and IndexError both inherit from LookupError

Correct Answer: (C)

[EN] Slicing in Python never raises `IndexError`; it safely adjusts bounds and returns an empty sequence.

[HI] पायथन में स्लाइसिंग `[1, 2][5:10]` कभी भी `IndexError` नहीं देती, बल्कि खाली लिस्ट `[]` लौटाती है।

Q17. Within Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError, which built-in exception directly maps to: "ArithmeticError; divisor 0 in /, //, %"?

(Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError में कौन सा Built-in Exception सीधे "ArithmeticError; divisor 0 in /, //, %" से संबंधित है?)

(A) KeyError

(B) ValueError

(C) ZeroDivisionError

(D) IndexError

Correct Answer: (C)

[EN] In Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError, 'ZeroDivisionError' handles 'ArithmeticError; divisor 0 in /, //, %' (Triggered even by float 5.0 / 0.0 and 0 ** -1).

[HI] Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError में 'ZeroDivisionError' का कार्य/विवरण 'ArithmeticError; divisor 0 in /, //, %' (Triggered even by float 5.0 / 0.0 and 0 ** -1) है।

Q18. Which option accurately describes 'ValueError' in Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError?

(Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError के संदर्भ में 'ValueError' की सही विशेषता कौन सी है?)

(A) ArithmeticError; divisor 0 in /, //, %

(B) LookupError; missing dict key / set.remove

(C) LookupError; out-of-range sequence index

(D) Exception; right type, invalid content

Correct Answer: (D)

[EN] 'ValueError' provides 'Exception; right type, invalid content' — key point: e.g. int('3.14'), math.sqrt(-1), [1].remove(9).

[HI] 'ValueError' का मुख्य विवरण 'Exception; right type, invalid content' है (e.g. int('3.14'), math.sqrt(-1), [1].remove(9))।

Q19. In Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError, identify the correct parameter for the specification: "LookupError; missing dict key / set.remove".

(Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError में "LookupError; missing dict key / set.remove" विवरण किस विकल्प के लिए सही है?)

(A) ZeroDivisionError

(B) IndexError

(C) KeyError

(D) ValueError

Correct Answer: (C)

[EN] 'KeyError' corresponds to 'LookupError; missing dict key / set.remove' (Avoid via dict.get(k, default) or defaultdict).

[HI] 'KeyError' का संबंध 'LookupError; missing dict key / set.remove' (Avoid via dict.get(k, default) or defaultdict) से है।

Q20. Considering Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError, what key behavior defines 'IndexError'?

(Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError में 'IndexError' की मुख्य भूमिका या मान क्या है?)

(A) LookupError; out-of-range sequence index

(B) LookupError; missing dict key / set.remove

(C) ArithmeticError; divisor 0 in /, //, %

(D) Exception; right type, invalid content

Correct Answer: (A)

[EN] 'IndexError' represents 'LookupError; out-of-range sequence index' (Slicing like [1, 2][5:9] returns [] without error).

[HI] 'IndexError' का अर्थ/मान 'LookupError; out-of-range sequence index' है (Slicing like [1, 2][5:9] returns [] without error)।

Common Built-in Exceptions: ZeroDivisionError, ValueError, KeyError, IndexError — Exam FAQs

Q1: Why does `int('3.14')` raise `ValueError` instead of returning `3`?

`int('3.14')` से `3` मिलने के बजाय `ValueError` क्यों आता है?

[EN] `int(str)` parses integer literals only (base-10 digits with optional sign). Because `'.'` is not a valid integer digit, `'3.14'` fails integer parsing with `ValueError`; convert via `int(float('3.14'))` if truncation from a decimal string is desired.

[HI] `int()` किसी स्ट्रिंग में केवल पूर्णांक अंक पढ़ता है, दशमलव बिंदु नहीं। इसलिए पहले `float('3.14')` से फ्लोट बनाकर फिर `int(float('3.14'))` करना होता है।

Q2: What is the quick exam rule to distinguish `ValueError` from `TypeError`?

परीक्षा में `ValueError` और `TypeError` में तुरंत अंतर पहचानने का सरल नियम क्या है?

[EN] Ask whether the argument's *type* is acceptable to the function. `int('xyz')` expects a `str` (type is fine, content is bad -> `ValueError`). `int([1, 2])` cannot accept a `list` at all (wrong type -> `TypeError`).

[HI] यह देखें कि क्या फंक्शन वह डेटा टाइप स्वीकार करता है: `int('xyz')` में `str` टाइप सही है पर सामग्री गलत है -> `ValueError`। वहीं `int([1, 2])` में `list` टाइप ही अमान्य है -> `TypeError`।

Q3: Why does Python raise `ZeroDivisionError` on `1.0 / 0.0` instead of returning `inf` like NumPy or C?

पायथन NumPy या C की तरह `1.0 / 0.0` पर `inf` देने के बजाय `ZeroDivisionError` क्यों देता है?

[EN] Python's design philosophy treats silent infinity propagation in general-purpose scalar math as dangerous for catching logic bugs early. Therefore, standard Python raises `ZeroDivisionError`, whereas vectorized libraries like NumPy follow IEEE 754 warnings returning `inf`.

[HI] पायथन के डिज़ाइन में सामान्य स्केलर गणित में चुपचाप `inf` बनने को बग छिपाने वाला माना जाता है ताकि त्रुटि तुरंत पकड़ी जाए; जबकि वैज्ञानिक लाइब्रेरी NumPy में IEEE 754 अनुसार `inf` मिल सकता है।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)