PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Python Fundamental Data Types: int, float, complex, bool, str (पायथन डेटा प्रकार: int (असीमित आकार), float, complex (a + bj), bool) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: Python's five core built-in scalar/text types—`int`, `float`, `complex`, `bool`, and `str`—are all immutable objects on the heap. Python `int` offers unlimited arbitrary precision, `float` uses 64-bit IEEE 754 double precision, `complex` stores `a + bj` pairs, `bool` subclasses `int` (`True == 1`), and `str` stores immutable Unicode character sequences.
अध्याय सार: पायथन के पाँच प्रमुख मूलभूत डेटा प्रकार—`int`, `float`, `complex`, `bool` और `str`—सभी इम्यूटेबल (अपरिवर्तनीय) ऑब्जेक्ट्स हैं। `int` असीमित आकार का होता है, `float` 64-बिट IEEE 754 डबल-प्रिसिजन पर चलता है, `complex` को `a + bj` से लिखते हैं, `bool` (`True == 1`) `int` की सब-क्लास है, और `str` इम्यूटेबल Unicode टेक्स्ट है।
Python Fundamental Data Types: int, float, complex, bool, str: Detailed Notes & Architecture (पायथन डेटा प्रकार: int (असीमित आकार), float, complex (a + bj), bool)
1. Arbitrary-Precision Integers (int) (असीमित आकार के पूर्णांक (int))
[EN] Python 3's `int` handles positive, negative, and zero whole numbers with **arbitrary precision**—there is no 32-bit or 64-bit overflow because CPython dynamically allocates extra memory digits as needed up to available RAM. Integer literals support base prefixes: binary `0b`/`0B` (`0b1010 == 10`), octal `0o`/`0O` (`0o12 == 10`), and hexadecimal `0x`/`0X` (`0xA == 10`), plus underscore separators (`1_000_000`, PEP 515) for readability. Conversions like `int("101", 2)` parse base-N strings, while `int(3.9)` truncates toward zero yielding `3`.
[HI] पायथन 3 का `int` **असीमित प्रिसिजन** वाला होता है—इसमें C/Java जैसा 32-बिट या 64-बिट ओवरफ्लो नहीं होता, बल्कि उपलब्ध RAM तक कितनी भी बड़ी संख्या स्टोर की जा सकती है। इंटीजर लिटरल बाइनरी (`0b1010`), ऑक्टल (`0o12`) और हेक्साडेसिमल (`0xA`) प्रीफिक्स तथा पठनीयता के लिए अंडरस्कोर (`1_000_000`) सपोर्ट करते हैं। `int(3.9)` दशमलव भाग काटकर `3` देता है और `int("101", 2)` किसी भी बेस की स्ट्रिंग को `int` में बदलता है।
2. IEEE 754 Floating-Point Numbers (float) (IEEE 754 फ्लोटिंग-पॉइंट संख्याएँ (float))
[EN] In CPython, `float` wraps a C `double`, implementing **64-bit IEEE 754 double precision** (~15–17 significant decimal digits and exponent range up to roughly `1.8e308`; inspect exact bounds via `sys.float_info`). Literals include decimal fractions (`3.14`) and scientific notation (`2.5e-4`), along with special values `float('inf')`, `float('-inf')`, and `float('nan')` (remember `nan != nan`). Because base-2 binary cannot represent `0.1` or `0.2` exactly, `0.1 + 0.2 == 0.30000000000000004` (`False` when compared to `0.3`); use `math.isclose()` or `decimal.Decimal` for exact decimal math.
[HI] CPython में `float` **64-बिट IEEE 754 डबल-प्रिसिजन** मानक का उपयोग करता है (लगभग 15–17 सार्थक अंक, विवरण `sys.float_info` में)। इसमें वैज्ञानिक संकेतन (`2.5e-4`) के अलावा विशेष मान `float('inf')`, `float('-inf')` और `float('nan')` होते हैं (`nan == nan` हमेशा `False` होता है)। बाइनरी फ्लोटिंग-पॉइंट अशुद्धि के कारण `0.1 + 0.2 == 0.3` `False` आता है; सटीक तुलना के लिए `math.isclose()` या `decimal.Decimal` उपयोग करें।
3. Complex Numbers (complex) and Boolean Subtype (bool) (कॉम्प्लेक्स नंबर (complex) और बूलियन सबटाइप (bool))
[EN] Python provides native complex numbers in the form `a + bj` or `a + bJ` (note: imaginary unit MUST be `j`/`J`, never `i`; if coefficient is 1, write `1j`, not bare `j`). Internally, both `.real` and `.imag` attributes are stored as 64-bit `float`s (`(3 + 4j).real == 3.0`), `.conjugate()` flips the imaginary sign, `abs(3 + 4j)` computes `5.0`, and relational ordering (`<`, `>`) raises `TypeError`. The `bool` type has literals `True` and `False` and is explicitly a **subclass of `int`** (`issubclass(bool, int)` is `True`), where `True == 1` and `False == 0` (`True + True == 2`).
[HI] पायथन में कॉम्प्लेक्स संख्याएँ `a + bj` या `a + bJ` के रूप में लिखी जाती हैं (काल्पनिक इकाई हमेशा `j`/`J` होती है, `i` नहीं)। इसके `.real` और `.imag` दोनों भाग `float` होते हैं; `abs(3 + 4j)` इसका मापांक `5.0` देता है, जबकि `<` या `>` तुलना करने पर `TypeError` आता है। `bool` (`True`, `False`) वास्तव में **`int` की एक सब-क्लास** है (`issubclass(bool, int) == True`), जहाँ `True == 1` और `False == 0` होता है।
4. Immutable Unicode Strings (str) and Immutability Rule (इम्यूटेबल Unicode स्ट्रिंग्स (str) और अपरिवर्तनीयता)
[EN] Python 3's `str` is an ordered, **immutable** sequence of Unicode code points—Python has no distinct `char` type, so a single character like `'A'` is simply a `str` of length 1. Strings support positive/negative indexing (`s[0]`, `s[-1]`) and slicing (`s[1:4]`, `s[::-1]`), while item mutation (`s[0] = 'X'`) raises `TypeError: 'str' object does not support item assignment`. Crucially, ALL five fundamental types (`int`, `float`, `complex`, `bool`, `str`) are **immutable**; operations like `s.upper()` or `x += 1` always produce new objects rather than mutating existing ones in place.
[HI] पायथन 3 में `str` Unicode कैरेक्टर्स का एक व्यवस्थित और **इम्यूटेबल (Immutable)** अनुक्रम है; पायथन में अलग `char` टाइप नहीं होता (`'A'` भी लंबाई 1 की `str` है)। स्ट्रिंग्स इंडेक्सिंग (`s[-1]`) और स्लाइसिंग (`s[::-1]`) सपोर्ट करती हैं, पर `s[0] = 'X'` करने पर `TypeError` आता है। पाँचों मूलभूत प्रकार (`int`, `float`, `complex`, `bool`, `str`) **इम्यूटेबल** होते हैं—इनमें कोई भी बदलाव हमेशा नया ऑब्जेक्ट बनाता है।
Syntax, Formula & Technical Example (Python Fundamental Data Types: int, float, complex, bool, str)
big_n = 10**40 # Unlimited precision int
flt = 3.5e2 # 64-bit IEEE 754 float (350.0)
z = 3 + 4j # complex: j unit, never i
flag = True # bool is a subclass of int
txt = "Computersir" # Immutable Unicode str
print(abs(z), z.real, z.imag) # 5.0 3.0 4.0
print(issubclass(bool, int), True + 4, type(txt[0]))
Python Fundamental Data Types: int, float, complex, bool, str Quick Reference & Comparison Table
| Data Type | Technical Specification | Key Python 3 Exam Fact |
|---|---|---|
| int | Arbitrary-precision signed integer | No overflow; supports 0b, 0o, 0x and 1_000 |
| float | 64-bit IEEE 754 double precision | 0.1 + 0.2 != 0.3; supports inf and nan |
| complex | Pair of floats (real + imag j) | Uses j/J suffix; < and > raise TypeError |
| bool & str | bool(int subclass) & immutable Unicode | True == 1; no separate char type; s[0]='a' fails |
Python Fundamental Data Types: int, float, complex, bool, str Top 20 Bilingual MCQs with Answers
Q1. What is the maximum value an `int` can store in Python 3?
(पायथन 3 में `int` डेटा टाइप अधिकतम कितना बड़ा मान स्टोर कर सकता है?)
(A) `2**31 - 1` (32-bit signed limit)
(B) Unlimited (arbitrary precision, bounded only by available system RAM)
(C) `2**128 - 1`
(D) `2**63 - 1` (64-bit signed limit)
Correct Answer: (B)
[EN] Python 3 `int` dynamically expands memory words as numbers grow, eliminating fixed-width integer overflow.
[HI] पायथन 3 में `int` का आकार असीमित होता है और यह उपलब्ध RAM के अनुसार कितनी भी बड़ी संख्या रख सकता है।
Q2. Which imaginary suffix is required for Python `complex` literals, and what is `type((3 + 4j).real)`?
(पायथन के `complex` नंबर में कौन-सा काल्पनिक चिह्न अनिवार्य है, और `type((3 + 4j).real)` क्या होता है?)
(A) `i` only, and `.real` returns `float`
(B) `i` or `j`, and `.real` returns `int` (`3`)
(C) `j` or `J`, and `.real` returns `float` (`3.0`)
(D) `j` only, and `.real` returns `complex`
Correct Answer: (C)
[EN] Python follows engineering convention using `j`/`J`, and stores both `.real` and `.imag` components as IEEE 754 `float`s.
[HI] पायथन कॉम्प्लेक्स नंबर के लिए केवल `j` या `J` उपयोग करता है, और इसके `.real` व `.imag` हिस्से `float` होते हैं।
Q3. What is the output of `issubclass(bool, int)` and `True + True + False` in Python 3?
(पायथन 3 में `issubclass(bool, int)` और `True + True + False` का परिणाम क्या होता है?)
(A) `False` and `TypeError`
(B) `True` and `2`
(C) `False` and `2`
(D) `True` and `True`
Correct Answer: (B)
[EN] `bool` inherits directly from `int` with `True == 1` and `False == 0`, so arithmetic treats them as `1` and `0`.
[HI] `bool`, `int` की सब-क्लास है (`True` = 1, `False` = 0), इसलिए `issubclass(bool, int)` `True` और `True + True + False` का योग `2` आता है।
Q4. What is the result of `0.1 + 0.2 == 0.3` in standard Python?
(सामान्य पायथन में `0.1 + 0.2 == 0.3` का परिणाम क्या होता है?)
(A) `TypeError`
(B) `False` (because `0.1 + 0.2` evaluates to `0.30000000000000004` in IEEE 754 binary float)
(C) `True`
(D) `0.3`
Correct Answer: (B)
[EN] Base-10 fractions like `0.1` and `0.2` are repeating binary fractions in 64-bit IEEE 754 floats, causing tiny rounding error.
[HI] 64-बिट IEEE 754 बाइनरी फ्लोट में `0.1 + 0.2` सटीक `0.3` के बजाय `0.30000000000000004` बनता है, अतः तुलना `False` देती है।
Q5. In Python 3, what is `type('A')`?
(पायथन 3 में `type('A')` क्या होता है?)
(A) `<class 'str'>` (Python has no separate `char` data type)
(B) `<class 'char'>`
(C) `<class 'chr'>`
(D) `<class 'byte'>`
Correct Answer: (A)
[EN] Unlike C/C++/Java, Python represents single characters as strings (`str`) of length 1.
[HI] C/Java के विपरीत, पायथन में अलग `char` डेटा टाइप नहीं होता; एक अकेला अक्षर भी लंबाई 1 की `str` होती है।
Q6. What happens when you execute `s = "hello"; s[0] = "H"`?
(`s = "hello"; s[0] = "H"` निष्पादित करने पर क्या होता है?)
(A) `s` becomes `"Hello"`
(B) `SyntaxError`
(C) `TypeError: 'str' object does not support item assignment`
(D) `ValueError`
Correct Answer: (C)
[EN] Because `str` is immutable, characters cannot be modified in place by index assignment.
[HI] `str` इम्यूटेबल होती है, इसलिए इंडेक्स से अक्षर बदलने का प्रयास करने पर `TypeError` आता है।
Q7. What is the decimal value of the Python literal `0b1010 + 0o12 + 0xA`?
(पायथन में `0b1010 + 0o12 + 0xA` का दशमलव (decimal) मान क्या होगा?)
(A) `22`
(B) `30`
(C) `101012A`
(D) `SyntaxError`
Correct Answer: (B)
[EN] `0b1010` = 10 (binary), `0o12` = 10 (octal), and `0xA` = 10 (hexadecimal), summing to 30.
[HI] `0b1010` (बाइनरी 10), `0o12` (ऑक्टल 10) और `0xA` (हेक्साडेसिमल 10) का कुल योग `30` होता है।
Q8. What does `abs(3 + 4j)` return in Python?
(पायथन में `abs(3 + 4j)` क्या मान लौटाता है?)
(A) `TypeError`
(B) `5.0` (a `float` representing magnitude sqrt(3^2 + 4^2))
(C) `7`
(D) `3 + 4j`
Correct Answer: (B)
[EN] `abs()` on a `complex` number computes its Euclidean magnitude `sqrt(real^2 + imag^2)` as a `float`.
[HI] `complex` संख्या पर `abs()` लगाने से उसका मापांक `sqrt(3^2 + 4^2) = 5.0` (`float`) प्राप्त होता है।
Q9. What happens if you evaluate `(1 + 2j) < (3 + 4j)` in Python 3?
(पायथन 3 में `(1 + 2j) < (3 + 4j)` चलाने पर क्या होता है?)
(A) `TypeError: '<' not supported between instances of 'complex' and 'complex'`
(B) `True`
(C) `False`
(D) `(2 + 2j)`
Correct Answer: (A)
[EN] Complex numbers do not have a mathematical total ordering, so `<`, `<=`, `>`, and `>=` raise `TypeError` (only `==` and `!=` work).
[HI] कॉम्प्लेक्स संख्याओं की क्रम तुलना (`<`, `>`) परिभाषित नहीं होती, इसलिए यह `TypeError` देता है (केवल `==` और `!=` मान्य हैं)।
Q10. What does `float('nan') == float('nan')` evaluate to in Python?
(पायथन में `float('nan') == float('nan')` का परिणाम क्या होता है?)
(A) `TypeError`
(B) `True`
(C) `None`
(D) `False`
Correct Answer: (D)
[EN] Per the IEEE 754 standard, NaN (Not-a-Number) is never equal to anything, including itself; use `math.isnan(x)` to test for NaN.
[HI] IEEE 754 मानक के अनुसार `NaN` स्वयं के बराबर भी नहीं होता, इसलिए `nan == nan` हमेशा `False` देता है; जाँच के लिए `math.isnan()` उपयोग करें।
Q11. Which of the following evaluates to `True` when passed to `bool(...)`?
(निम्नलिखित में से किसे `bool(...)` में पास करने पर परिणाम `True` आएगा?)
(A) `bool("")`
(B) `bool(0)`
(C) `bool(0j)`
(D) `bool("False")`
Correct Answer: (D)
[EN] Any non-empty string—even `"False"` or `"0"`—is truthy (`True`), whereas `0`, `0.0`, `0j`, `""`, `[]`, `{}`, and `None` are falsy.
[HI] `"False"` एक गैर-खाली (non-empty) स्ट्रिंग है इसलिए `bool("False")` `True` होता है, जबकि `0`, `""` और `0j` `False` देते हैं।
Q12. What is the type of the result of `10 / 2` in Python 3?
(पायथन 3 में `10 / 2` के परिणाम का डेटा टाइप क्या होता है?)
(A) `float` (`5.0`)
(B) `int` (`5`)
(C) `complex`
(D) `bool`
Correct Answer: (A)
[EN] The single slash `/` operator always produces a `float` in Python 3, even when two integers divide evenly.
[HI] पायथन 3 में सिंगल स्लैश `/` से पूर्णतः विभाजित होने पर भी परिणाम हमेशा `float` (`5.0`) ही आता है।
Q13. What is the value and type of `1_000_000` in Python 3.6+?
(पायथन 3.6+ में `1_000_000` का मान और डेटा टाइप क्या होता है?)
(A) A `tuple` `(1, 0, 0)`
(B) `1000000` of type `int` (underscores act purely as visual digit separators)
(C) `SyntaxError`
(D) A `str` `'1_000_000'`
Correct Answer: (B)
[EN] PEP 515 permits single underscores between digits in numeric literals (`int`, `float`, `complex`) purely for readability.
[HI] PEP 515 के तहत अंकों के बीच अंडरस्कोर केवल पठनीयता के लिए होता है; `1_000_000` एक सामान्य `int` `1000000` है।
Q14. How many bits of precision does Python's built-in `float` use on standard 64-bit platforms?
(मानक 64-बिट प्लेटफ़ॉर्म पर पायथन का बिल्ट-इन `float` कितने बिट्स का उपयोग करता है?)
(A) 16 bits (half precision)
(B) 64 bits (IEEE 754 double precision)
(C) 32 bits (IEEE 754 single precision)
(D) Arbitrary unlimited bits like `int`
Correct Answer: (B)
[EN] Unlike `int`, Python's `float` is fixed-width 64-bit IEEE 754 double precision (about 15–17 decimal digits).
[HI] `int` के विपरीत, पायथन का `float` असीमित नहीं होता बल्कि 64-बिट IEEE 754 डबल प्रिसिजन का होता है।
Q15. What does `int(-3.9)` return in Python?
(पायथन में `int(-3.9)` क्या मान लौटाता है?)
(A) `-3.9`
(B) `-4` (floor rounding)
(C) `-3` (truncates toward zero)
(D) `ValueError`
Correct Answer: (C)
[EN] `int(x)` truncates fractional digits toward zero (giving `-3`), whereas `math.floor(-3.9)` returns `-4`.
[HI] `int(-3.9)` दशमलव भाग को शून्य की दिशा में काट देता है और `-3` लौटाता है (जबकि `math.floor` `-4` देता है)।
Q16. Which statement about Python's five fundamental data types (`int`, `float`, `complex`, `bool`, `str`) is NOT true?
(पायथन के पाँच मूलभूत डेटा टाइप्स (`int`, `float`, `complex`, `bool`, `str`) के बारे में कौन-सा कथन सत्य नहीं है?)
(A) All five types (`int`, `float`, `complex`, `bool`, `str`) are immutable
(B) `str` is mutable so characters can be updated in place via `s[i] = ch`
(C) `bool` is a subclass of `int` with `True == 1` and `False == 0`
(D) `int` supports arbitrarily large integers without fixed bit overflow
Correct Answer: (B)
[EN] Strings (`str`) in Python are strictly immutable, just like `int`, `float`, `complex`, and `bool`.
[HI] पायथन में `str` सहित सभी पाँच मूलभूत डेटा टाइप इम्यूटेबल होते हैं; `s[i] = ch` से स्ट्रिंग को इन-प्लेस बदला नहीं जा सकता।
Q17. Within Python Fundamental Data Types: int, float, complex, bool, str, which data type directly maps to: "Arbitrary-precision signed integer"?
(Python Fundamental Data Types: int, float, complex, bool, str में कौन सा Data Type सीधे "Arbitrary-precision signed integer" से संबंधित है?)
(A) int
(B) float
(C) complex
(D) bool & str
Correct Answer: (A)
[EN] In Python Fundamental Data Types: int, float, complex, bool, str, 'int' handles 'Arbitrary-precision signed integer' (No overflow; supports 0b, 0o, 0x and 1_000).
[HI] Python Fundamental Data Types: int, float, complex, bool, str में 'int' का कार्य/विवरण 'Arbitrary-precision signed integer' (No overflow; supports 0b, 0o, 0x and 1_000) है।
Q18. Which option accurately describes 'float' in Python Fundamental Data Types: int, float, complex, bool, str?
(Python Fundamental Data Types: int, float, complex, bool, str के संदर्भ में 'float' की सही विशेषता कौन सी है?)
(A) 64-bit IEEE 754 double precision
(B) bool(int subclass) & immutable Unicode
(C) Pair of floats (real + imag j)
(D) Arbitrary-precision signed integer
Correct Answer: (A)
[EN] 'float' provides '64-bit IEEE 754 double precision' — key point: 0.1 + 0.2 != 0.3; supports inf and nan.
[HI] 'float' का मुख्य विवरण '64-bit IEEE 754 double precision' है (0.1 + 0.2 != 0.3; supports inf and nan)।
Q19. In Python Fundamental Data Types: int, float, complex, bool, str, identify the correct parameter for the specification: "Pair of floats (real + imag j)".
(Python Fundamental Data Types: int, float, complex, bool, str में "Pair of floats (real + imag j)" विवरण किस विकल्प के लिए सही है?)
(A) float
(B) complex
(C) int
(D) bool & str
Correct Answer: (B)
[EN] 'complex' corresponds to 'Pair of floats (real + imag j)' (Uses j/J suffix; < and > raise TypeError).
[HI] 'complex' का संबंध 'Pair of floats (real + imag j)' (Uses j/J suffix; < and > raise TypeError) से है।
Q20. Considering Python Fundamental Data Types: int, float, complex, bool, str, what key behavior defines 'bool & str'?
(Python Fundamental Data Types: int, float, complex, bool, str में 'bool & str' की मुख्य भूमिका या मान क्या है?)
(A) bool(int subclass) & immutable Unicode
(B) Arbitrary-precision signed integer
(C) 64-bit IEEE 754 double precision
(D) Pair of floats (real + imag j)
Correct Answer: (A)
[EN] 'bool & str' represents 'bool(int subclass) & immutable Unicode' (True == 1; no separate char type; s[0]='a' fails).
[HI] 'bool & str' का अर्थ/मान 'bool(int subclass) & immutable Unicode' है (True == 1; no separate char type; s[0]='a' fails)।
Python Fundamental Data Types: int, float, complex, bool, str — Exam FAQs
Q1: Why are `int`, `float`, `complex`, `bool`, and `str` all immutable in Python?
पायथन में `int`, `float`, `complex`, `bool` और `str` सभी इम्यूटेबल (अपरिवर्तनीय) क्यों होते हैं?
[EN] Immutability guarantees value safety across aliases, enables safe dictionary/set hashing (`__hash__`), and lets CPython cache/intern common values like small ints and short strings without unintended side effects.
[HI] इम्यूटेबल होने से एलियास में वैल्यू सुरक्षित रहती है, ये `dict` की कुंजी (`hash`) बन सकते हैं, और CPython इन्हें सुरक्षित रूप से मेमोरी में कैश/इंटरन कर पाता है।
Q2: Why does Python use `j` instead of `i` for complex numbers?
पायथन कॉम्प्लेक्स संख्याओं के लिए `i` के बजाय `j` का उपयोग क्यों करता है?
[EN] Python follows electrical engineering and physics convention where `i` represents electric current, so `j` denotes the imaginary unit sqrt(-1). Note that `1j` requires the `1` prefix so `j` alone remains usable as a variable name.
[HI] इलेक्ट्रिकल इंजीनियरिंग में `i` करंट के लिए प्रयुक्त होता है, इसलिए पायथन `j` उपयोग करता है। ध्यान रखें कि काल्पनिक इकाई लिखने के लिए `1j` लिखना जरूरी है ताकि अकेला `j` वेरिएबल नाम बन सके।
Q3: How do I perform exact base-10 financial arithmetic without float rounding errors like `0.1 + 0.2 != 0.3`?
`0.1 + 0.2 != 0.3` जैसी फ्लोटिंग-पॉइंट त्रुटि के बिना सटीक वित्तीय गणना कैसे करें?
[EN] Use Python's built-in `decimal.Decimal` module initialized from strings, e.g., `Decimal('0.1') + Decimal('0.2') == Decimal('0.3')`.
[HI] बिल्ट-इन `decimal` मॉड्यूल से स्ट्रिंग पास करके `Decimal('0.1') + Decimal('0.2')` का उपयोग करें, जो सटीक बेस-10 दशमलव गणना देता है।
Post a Comment
Post a Comment