📑 Table of Contents — किसी भी topic पर सीधे जाएँ
Python क्या है? — History व आज का सबसे बड़ा नाम
📜 Python का सफ़र
- 1991: Python 1.0 — Guido van Rossum (Netherlands) ने release की।
- 2000: Python 2.0 आई (अब पुरानी हो चुकी, 2020 में support खत्म)।
- 2008: Python 3.0 — आज हम सब यही version use करते हैं।
- आज: दुनिया की No.1 popular language — Google, Netflix, NASA, Instagram सब use करते हैं!
🌍 Python कहाँ-कहाँ उपयोग होता है?
| क्षेत्र | उपयोग |
|---|---|
| Web Development | Django, Flask frameworks से websites |
| Data Science | Data analysis, visualization (Pandas, NumPy) |
| AI / Machine Learning | ChatGPT जैसे AI models (TensorFlow, PyTorch) |
| Automation | Boring कामों को script से automatic करना |
| App / Game Development | Desktop apps, simple games (Pygame) |
🎉 आपका पहला Python Program
print("Hello World")Features of Python — यह इतनी Popular क्यों है?
| # | Feature | मतलब |
|---|---|---|
| 1 | Simple & Easy to Learn | English जैसा syntax — जल्दी सीखा जा सकता है |
| 2 | High-Level | Memory management जैसी low-level details की चिंता नहीं |
| 3 | Interpreted | Line-by-line execution — debugging आसान |
| 4 | Dynamically Typed | Data type declare करने की ज़रूरत नहीं |
| 5 | Platform Independent | Windows/Linux/Mac — एक code सबपर चले |
| 6 | Open Source | बिल्कुल free — कोई भी use व modify कर सकता है |
| 7 | Object-Oriented | Class व object concepts को support करता है |
| 8 | Large Standard Library | हज़ारों ready-made libraries (math, random...) |
| 9 | Extensible & Embeddable | C/C++ के साथ integrate हो सकता है |
| 10 | Portable | Program एक system से दूसरे पर आसानी से जाए |
x = 10 # x abhi integer hai print(type(x)) x = "Hello" # ab wahi x string ban gaya! print(type(x))
<class 'str'>
Interpreted व Dynamically Typed — दो सबसे बड़ी पहचान
⚡ Python = Interpreted
- Code line-by-line execute होता है — कोई अलग compile step नहीं।
- Error आते ही वहीं रुक जाता है — debugging आसान।
- Compiled languages (C, C++) में पूरा program पहले compile होकर .exe बनता है — execution fast पर बदलाव में compile दोबारा।
🔄 Dynamic vs Static Typing
| आधार | Dynamic Typing (Python) | Static Typing (C, Java) |
|---|---|---|
| Type कब तय होता है | Runtime पर, value से | पहले declare करना पड़ता है |
| Declaration | x = 10 — बस! | int x = 10; |
| Type बदलना | allowed — x = "Hello" चलेगा | Error देगा |
| Type check | Runtime पर | Compile time पर |
data = 100 # int print(data, type(data)) data = 3.14 # float print(data, type(data)) data = "Python" # string print(data, type(data))
3.14 <class 'float'>
Python <class 'str'>
Python Tokens — Program की सबसे छोटी इकाइयाँ
1️⃣ Keywords (Reserved Words)
Python के reserved words जिनका fixed meaning है — इन्हें variable नाम नहीं बना सकते। Case-sensitive हैं (True चलेगा, true नहीं)।
False True None and or not if else elif for while break continue pass def return class import from try except finally in is lambda
import keyword
print(keyword.kwlist)
print("Total:", len(keyword.kwlist))Total: 35
2️⃣ Identifiers (नाम)
Variables, functions, classes को दिए गए नाम। Rules तोड़े तो SyntaxError!
| Rule | ✔ Valid | ✘ Invalid |
|---|---|---|
| Alphabet या _ से शुरू हो | name, _age | 2num (digit से शुरू) |
| Digit से शुरू नहीं | num2 | 2num |
| Special symbols नहीं (@#$%) | total_marks | total@marks |
| Keyword नहीं हो सकता | class_name | class |
| Case-sensitive | Name व name अलग हैं | — |
total_marks, न कि tm); snake_case (my_variable_name); constants UPPERCASE (PI = 3.14)।3️⃣ Literals (Fixed Values)
x = 10 # integer literal pi = 3.14 # float literal name = "Ram" # string literal flag = True # boolean literal empty = None # special literal
4️⃣ Operators व 5️⃣ Punctuators
a = 5 + 3 # = aur + operators hain
# Punctuators: ( ) { } [ ] : ; ,
# jaise print("Hi") me ( ) aur " "marks = eng + math इस line में — marks, eng, math = identifiers; =, + = operators। पूरी line 5 tokens से बनी! (Operators की पूरी detail Chapter 4 में आएगी।)Program Structure व Indentation — Python की सबसे अलग बात
{ } से बनते हैं — Python में Indentation (spaces) से! गलत indentation = IndentationError। यही Python के code को इतना साफ़-सुथरा बनाता है।🏗️ Program के मुख्य हिस्से
- Comments: # से — code की explanation (interpreter ignore करता है)।
- Statements: Instructions — हर statement नई line में।
- Indentation: 4 spaces — block define करने के लिए (braces { } नहीं)।
- Input/Output: input() व print()।
# simple python program (yah comment hai)
name = input("Enter your name: ")
if name:
print("Hello", name) # 4 spaces indentation = if ka block
print("Welcome!") # yah bhi if ke andar hai
print("Bye") # indentation nahi = if ke baharWelcome!
Bye
if True:
print("Hello") # indentation nahi diya!Variables व Object References — Python का असली Model
Variable = Object पर लगा Label
a = 10 b = a # b bhi USI object ko refer karta hai print(id(a) == id(b)) # kya dono same object par hain?
🎁 Multiple Assignment — एक line में कई काम
a, b, c = 1, 2, 3 # alag-alag values print(a, b, c) x = y = z = 5 # sabko same value print(x, y, z) p, q = 10, 20 p, q = q, p # Python-style swap (Ch.2 wale temp ki zaroorat nahi!) print(p, q)
5 5 5
20 10
🔒 Constants — Convention से
PI = 3.14 GRAVITY = 9.8 # Python me real constant keyword NAHI hota — # technically value badal sakti hai, par programmer nahi badalta (convention)
Data Types — हर Value की अपनी जाति
📦 Built-in Data Types का नक्शा
| Category | Types | Example |
|---|---|---|
| Numeric | int, float, complex | 10, 3.14, 2+3j |
| Boolean | bool | True, False |
| Sequence | str, list, tuple | "Hi", [1,2], (1,2) |
| Mapping | dict | {"a": 1} |
| Set | set | {1, 2, 3} |
| None | NoneType | None |
🔢 1. Numeric Types
a = 10 b = -5 big = 99999999999999999999 # Python me koi limit nahi! print(a, b, big)
x = 3.14 y = 1.2e3 # 1.2 × 10³ = 1200.0 print(x, y)
z = 2 + 3j print(z.real, z.imag)
🔢 Integer के अलग रूप — Binary, Octal, Hex
a = 0b1010 # Binary (base 2) b = 0o12 # Octal (base 8) c = 0xA # Hexadecimal (base 16) print(a, b, c) # teeno = 10!
⚠️ Float Precision Issue — Exam का Famous Question
print(0.1 + 0.2) print(round(0.1 + 0.2, 2)) # samadhan: round()
0.3
✅ 2. Boolean — सिर्फ True या False
x = 10 print(x > 5) # True print(True + True) # surprise! True = 1 hota hai print(False * 10) # False = 0
2
0
🔤 3. String — Characters का Sequence
name = "Python" print(name[0]) # pehla character (index 0 se) print(name[1:4]) # index 1 se 3 tak (4 shamil nahi) print(name + " 3") # concatenation print(name * 2) # repetition print(name.upper()) # method
yth
Python 3
PythonPython
PYTHON
⬜ 4. NoneType — "कुछ नहीं" वाला Type
x = None print(x) print(type(x)) print(x == 0) # None zero NAHI hai!
<class 'NoneType'>
False
Mutable vs Immutable — बदलेगा या नया बनेगा?
x = 10
print("Pehle:", id(x))
x = x + 5
print("Baad me:", id(x)) # ALAG id — naya object bana!Baad me: 140711234568050
← दोनों id अलग (आपके system पर numbers अलग होंगे)
x = [1, 2, 3]
print("Pehle:", id(x))
x.append(4)
print("Baad me:", id(x)) # SAME id — wahi object badla!
print(x)Baad me: 140711234599999
[1, 2, 3, 4]
← id same रही
| Immutable (नया object बनता है) | Mutable (वही object बदलता है) |
|---|---|
| int, float, str, tuple, bool | list, dict, set |
Type Checking व Conversion — Type जानना और बदलना
🔍 Type Checking — type() व isinstance()
x = 10 print(type(x)) # exact type batata hai print(isinstance(x, int)) # True/False deta hai print(isinstance(x, str)) # kya x string hai?
True
False
🔄 Type Conversion के 2 तरीके
1️⃣ Implicit (Automatic) — Python खुद करे
x = 10 # int y = 2.5 # float result = x + y print(result, type(result))
2️⃣ Explicit (Manual) — Programmer खुद करे
x = "10"
y = int(x) # string -> int
print(y + 5, type(y))
print(float("3.5")) # string -> float
print(str(100) + "%") # int -> string
print(bool(0), bool(5)) # 0 = False, baaki sab True3.5
100%
False True
print(int("abc")) # "abc" number nahi ban sakta!Input व Output — User से बातचीत
age = input("Enter age: ") # user ne 20 dala
print(age + 5) # ERROR aayega!← "20" string है, उसमें 5 नहीं जुड़ सकता!
age = int(input("Enter age: "))
print("5 saal baad aap", age + 5, "ke honge")🖨️ print() के तरीके
name = "Rahul"
marks = 92
print(f"My name is {name} and I scored {marks}%")
print(f"Half marks = {marks / 2}") # andar calculation bhi!Half marks = 46.0
print("Boosting", "Skills", sep="-")
print("Hello", end=" ")
print("World") # nayi line nahi mili, saath chhapaHello World
Memory Management व Garbage Collection — सफाई अपने आप
🧠 Memory Management के Key Concepts
- Automatic Allocation: value assign करते ही Python खुद memory देता है।
- Heap Memory: सभी objects heap में store होते हैं।
- Reference Counting: Python गिनता रहता है कि object को कितने variables refer कर रहे हैं।
- Garbage Collection: reference count 0 होते ही object की memory free!
x = 10 # object 10 ka reference count = 1
x = None # ab 10 ko koi refer nahi karta (count = 0)
# -> Garbage Collector memory free kar dega!
print(x)🎯 Output-Based Questions — इस Chapter के Topics से
Q1. type() की पहचान
print(type(10/2)) print(type(10//2))
<class 'int'>
← / हमेशा float देता है (5.0), // integer (5)।
Q2. input() का String खेल
a = input() b = input() print(a + b)
← input() strings देता है — "5" + "5" = "55" (concatenation, जोड़ नहीं!)।
Q3. Boolean की Math
print(True + True + False) print(True * 5)
5
← True = 1, False = 0 — इसलिए 1+1+0 = 2 और 1×5 = 5।
Q4. String Indexing
s = "BOOSTING" print(s[0], s[3]) print(s[2:5]) print(s[-1])
OST
G
← Index 0 से; s[2:5] = index 2,3,4; s[-1] = आखिरी character।
Q5. Number Systems
print(0b101 + 0o10 + 0x10)
← 0b101 = 5, 0o10 = 8, 0x10 = 16 → 5+8+16 = 29।
Q6. Type Conversion Chain
x = "7" y = int(x) + float(x) print(y, type(y))
← 7 + 7.0 = int + float → implicit conversion से float।
Q7. Immutability का Error
name = "Python" name[0] = "J" print(name)
← String immutable है — किसी index पर value assign नहीं कर सकते।
Q8. Multiple Assignment
a, b, c = 5, 10, 15 a, c = c, a print(a, b, c)
← a और c swap हुए, b वहीं रहा।
Q9. f-string के अंदर Calculation
x = 4
print(f"Square of {x} is {x ** 2}")← f-string के {} में expressions भी evaluate होते हैं।
Q10. None की तुलना
x = None print(x == 0) print(x == "") print(x == None)
False
True
← None सिर्फ None के बराबर है — न 0 के, न empty string के।
Q11. Identifier Valid या Invalid?
_name = "A" # Line 1 2marks = 50 # Line 2 total_marks = 90 # Line 3 class = "10th" # Line 4
Q12. sep और end का Combo
print("A", "B", sep="*", end="#")
print("C")← sep="*" ने A-B के बीच * लगाया; end="#" ने newline की जगह # — इसलिए C उसी line में।
💻 Practice Programs — Chapter 3 के Concepts पर
Program 1 — Student Introduction Card (f-string)
name = input("Naam: ")
age = int(input("Age: "))
city = input("City: ")
print(f"--- Student Card ---")
print(f"Naam : {name}")
print(f"Age : {age} saal (next year: {age + 1})")
print(f"City : {city}")Naam : Rahul
Age : 17 saal (next year: 18)
City : Lucknow
Program 2 — Marks Percentage Calculator
obtained = float(input("Obtained marks: "))
total = float(input("Total marks: "))
percent = (obtained / total) * 100
print(f"Percentage = {round(percent, 2)}%")Program 3 — Type Explorer
values = [10, 3.14, "Hello", True, None, 2+3j]
for v in values:
print(v, "->", type(v))3.14 -> <class 'float'>
Hello -> <class 'str'>
True -> <class 'bool'>
None -> <class 'NoneType'>
(2+3j) -> <class 'complex'>
Program 4 — Number System Converter
n = int(input("Decimal number: "))
print(f"Binary : {bin(n)}")
print(f"Octal : {oct(n)}")
print(f"Hexadecimal : {hex(n)}")Octal : 0o31
Hexadecimal : 0x19
Program 5 — KM to Miles Converter
CONVERSION_FACTOR = 0.621371 # constant (UPPERCASE)
km = float(input("Kilometers: "))
miles = km * CONVERSION_FACTOR
print(f"{km} km = {round(miles, 2)} miles")Program 6 — String Playground
text = input("Kuchh likhiye: ")
print(f"Uppercase : {text.upper()}")
print(f"Lowercase : {text.lower()}")
print(f"Length : {len(text)} characters
Pehla : {text[0]} | Aakhri: {text[-1]}")Lowercase : boosting
Length : 8 characters
Pehla : B | Aakhri: g
Program 7 — Currency Note Value (bool as number)
a = 10
b = 25
c = 30
# 20 se bade kitne numbers hain?
count = (a > 20) + (b > 20) + (c > 20)
print("20 se bade numbers:", count)← False + True + True = 0+1+1 = 2 — boolean की math!
Program 8 — Simple Bill with Type Conversion
item = input("Item ka naam: ")
price = float(input("Price (per piece): "))
qty = int(input("Quantity: "))
total = price * qty
print(f"\n--- BILL ---")
print(f"{item} x {qty} = Rs. {total}")
print(f"GST (18%) = Rs. {round(total * 0.18, 2)}")
print(f"Grand Total = Rs. {round(total * 1.18, 2)}")Pen x 4 = Rs. 50.0
GST (18%) = Rs. 9.0
Grand Total = Rs. 59.0
Summary — Quick Revision (Exam से पहले पढ़ें)
- Python — Guido van Rossum, 1991; high-level, interpreted, general-purpose; उपयोग: Web, Data Science, AI, Automation।
- Features: Simple, Interpreted, Dynamically Typed, Platform Independent, Open Source, OOP, Large Library, Extensible, Portable।
- Tokens के 5 types: Keywords (35 reserved words), Identifiers (नाम — digit से शुरू नहीं, keyword नहीं), Literals, Operators, Punctuators।
- Indentation (4 spaces) से blocks बनते हैं — braces { } नहीं; गलती पर IndentationError।
- Variable = object का reference (label); a, b = b, a से swap; constants UPPERCASE convention से।
- Data Types: int (unlimited), float (precision issue: 0.1+0.2), complex (j), bool (True=1, False=0), str (immutable), None (NoneType)।
- Number systems: 0b binary, 0o octal, 0x hex; bin()/oct()/hex() से conversion।
- Immutable: int, float, str, tuple, bool; Mutable: list, dict, set — पहचान id() से।
- Conversion: Implicit (int+float→float, खुद), Explicit (int(), float(), str(), bool() — programmer)।
- input() हमेशा string देता है; print() में sep, end; f-string में {} के अंदर variables व calculations।
- Memory: automatic; objects heap में; Garbage Collection reference counting से (count 0 = free)।
Model Questions — 50 MCQs + 15 Theory Questions
❓ A. Multiple Choice Questions (50)
| # | प्रश्न व उत्तर |
|---|---|
| 1 | Python को किसने बनाया? (a) Dennis Ritchie(b) Guido van Rossum(c) James Gosling(d) Alan Turing ✔ सही उत्तर: (b) Guido van Rossum |
| 2 | Python कब release हुई? (a) 1985(b) 1991(c) 2000(d) 2008 ✔ सही उत्तर: (b) 1991 |
| 3 | Python का नाम आया — (a) साँप से(b) Monty Python comedy show से(c) Guido के dog से(d) Greek word से ✔ सही उत्तर: (b) Monty Python show से |
| 4 | Python है — (a) Low-level(b) High-level, interpreted(c) Assembly(d) Machine language ✔ सही उत्तर: (b) High-level, interpreted |
| 5 | Python में variable का type declare — (a) करना ज़रूरी है(b) नहीं करना पड़ता (dynamic typing)(c) सिर्फ int के लिए(d) function में ✔ सही उत्तर: (b) नहीं करना पड़ता |
| 6 | "एक बार लिखो, हर OS पर चलाओ" — यह feature है — (a) Open Source(b) Platform Independent(c) OOP(d) Extensible ✔ सही उत्तर: (b) Platform Independent |
| 7 | Python में कुल keywords लगभग हैं — (a) 15(b) 35(c) 100(d) 50 ✔ सही उत्तर: (b) 35keyword.kwlist से देख सकते हैं। |
| 8 | इनमें से keyword नहीं है — (a) if(b) while(c) print(d) else ✔ सही उत्तर: (c) printयह built-in function है, keyword नहीं। |
| 9 | Keywords होते हैं — (a) Case-insensitive(b) Case-sensitive(c) Numbers(d) Symbols ✔ सही उत्तर: (b) Case-sensitiveTrue चलेगा, true नहीं। |
| 10 | Valid identifier है — (a) 2num(b) my@var(c) _age(d) class ✔ सही उत्तर: (c) _age |
| 11 | Invalid identifier है — (a) name2(b) total_marks(c) 2marks(d) _temp ✔ सही उत्तर: (c) 2marksdigit से शुरू नहीं हो सकता। |
| 12 | Tokens के कितने types होते हैं? (a) 3(b) 4(c) 5(d) 7 ✔ सही उत्तर: (c) 5Keywords, Identifiers, Literals, Operators, Punctuators। |
| 13 | x = 10 में 10 है — (a) Identifier(b) Keyword(c) Literal(d) Punctuator ✔ सही उत्तर: (c) Literal |
| 14 | ( ), { }, [ ], : कहलाते हैं — (a) Operators(b) Punctuators(c) Literals(d) Keywords ✔ सही उत्तर: (b) Punctuators |
| 15 | Python में code blocks बनते हैं — (a) { } से(b) Indentation से(c) ( ) से(d) begin-end से ✔ सही उत्तर: (b) Indentation से |
| 16 | Standard indentation है — (a) 2 spaces(b) 4 spaces(c) 8 spaces(d) 1 tab अनिवार्य ✔ सही उत्तर: (b) 4 spaces |
| 17 | गलत indentation पर आती है — (a) ValueError(b) TypeError(c) IndentationError(d) NameError ✔ सही उत्तर: (c) IndentationError |
| 18 | Python में variable होता है — (a) Value का डिब्बा(b) Object का reference/label(c) Memory address(d) Keyword ✔ सही उत्तर: (b) Object का reference |
| 19 | Object की memory identity देता है — (a) type()(b) id()(c) len()(d) ref() ✔ सही उत्तर: (b) id() |
| 20 | a, b, c = 1, 2, 3 कहलाता है — (a) Swapping(b) Multiple assignment(c) Casting(d) Nesting ✔ सही उत्तर: (b) Multiple assignment |
| 21 | Python में swap का shortcut — (a) swap(a,b)(b) a, b = b, a(c) temp ज़रूरी(d) असंभव ✔ सही उत्तर: (b) a, b = b, a |
| 22 | Python में constant के लिए — (a) const keyword है(b) final keyword है(c) कोई keyword नहीं — UPPERCASE convention(d) #define ✔ सही उत्तर: (c) कोई keyword नहीं |
| 23 | Python में int की size — (a) 2 bytes(b) 4 bytes(c) 8 bytes(d) Unlimited ✔ सही उत्तर: (d) Unlimited |
| 24 | 1.2e3 की value है — (a) 1.23(b) 1200.0(c) 123(d) 0.0012 ✔ सही उत्तर: (b) 1200.01.2 × 10³। |
| 25 | Complex number में imaginary part के लिए — (a) i(b) j(c) k(d) x ✔ सही उत्तर: (b) jजैसे 2+3j। |
| 26 | 0b1010 की decimal value — (a) 1010(b) 10(c) 12(d) 8 ✔ सही उत्तर: (b) 10binary 1010। |
| 27 | 0x prefix दर्शाता है — (a) Binary(b) Octal(c) Hexadecimal(d) Decimal ✔ सही उत्तर: (c) Hexadecimal |
| 28 | print(0.1 + 0.2) का output — (a) 0.3(b) 0.30000000000000004(c) Error(d) 0.33 ✔ सही उत्तर: (b) 0.30000000000000004float precision issue। |
| 29 | True + True का मान — (a) TrueTrue(b) 2(c) True(d) Error ✔ सही उत्तर: (b) 2True = 1। |
| 30 | bool(0) का मान — (a) True(b) False(c) 0(d) Error ✔ सही उत्तर: (b) Falseसिर्फ 0 false, बाकी numbers true। |
| 31 | String होती है — (a) Mutable(b) Immutable(c) दोनों(d) Numeric ✔ सही उत्तर: (b) Immutable |
| 32 | s = "Python" में s[0] — (a) n(b) P(c) y(d) Error ✔ सही उत्तर: (b) Pindexing 0 से। |
| 33 | s[-1] देता है — (a) पहला character(b) आखिरी character(c) Error(d) खाली string ✔ सही उत्तर: (b) आखिरी character |
| 34 | "Hi" * 3 का output — (a) HiHiHi(b) Hi3(c) Error(d) 6 ✔ सही उत्तर: (a) HiHiHirepetition। |
| 35 | None का data type — (a) int(b) bool(c) NoneType(d) null ✔ सही उत्तर: (c) NoneType |
| 36 | None == 0 का मान — (a) True(b) False(c) Error(d) None ✔ सही उत्तर: (b) FalseNone सिर्फ None के बराबर। |
| 37 | Immutable type है — (a) list(b) dict(c) tuple(d) set ✔ सही उत्तर: (c) tuple |
| 38 | Mutable type है — (a) int(b) str(c) list(d) tuple ✔ सही उत्तर: (c) list |
| 39 | list में append के बाद id() — (a) बदल जाती है(b) same रहती है(c) 0 हो जाती है(d) Error ✔ सही उत्तर: (b) same रहती हैmutable, वही object बदला। |
| 40 | Variable का exact type बताता है — (a) isinstance()(b) type()(c) id()(d) print() ✔ सही उत्तर: (b) type() |
| 41 | isinstance(10, int) का output — (a) int(b) True(c) 10(d) class int ✔ सही उत्तर: (b) Trueयह True/False देता है। |
| 42 | int + float का result होता है — (a) int(b) float(c) str(d) Error ✔ सही उत्तर: (b) floatimplicit conversion। |
| 43 | int("abc") करने पर — (a) 0(b) abc(c) ValueError(d) None ✔ सही उत्तर: (c) ValueError |
| 44 | int() जैसी manual conversion कहलाती है — (a) Implicit(b) Explicit(c) Automatic(d) Dynamic ✔ सही उत्तर: (b) Explicit |
| 45 | input() function return करता है — (a) int(b) float(c) हमेशा string(d) user पर निर्भर ✔ सही उत्तर: (c) हमेशा string |
| 46 | input से number लेने का सही तरीका — (a) input(int)(b) int(input())(c) number(input())(d) input().int ✔ सही उत्तर: (b) int(input()) |
| 47 | print("A","B",sep="-") का output — (a) A B(b) A-B(c) AB(d) A,B ✔ सही उत्तर: (b) A-B |
| 48 | print में newline की जगह कुछ और लगाने के लिए — (a) sep(b) end(c) stop(d) next ✔ सही उत्तर: (b) end |
| 49 | f"..." string में variables लिखते हैं — (a) ( ) में(b) { } में(c) [ ] में(d) <> में ✔ सही उत्तर: (b) { } मेंf-string formatting। |
| 50 | Python में garbage collection आधारित है — (a) Manual free() पर(b) Reference counting पर(c) Programmer पर(d) delete keyword पर ✔ सही उत्तर: (b) Reference counting परcount 0 = memory free। |
📝 B. 15 Theory Questions (Short Answers)
- Python क्या है? इसे किसने और कब बनाया?Python एक high-level, interpreted, general-purpose language है — Guido van Rossum ने 1991 में बनाई। नाम Monty Python comedy show से आया।
- Python के कोई 5 features लिखिए।Simple व Easy to Learn; Interpreted (line-by-line); Dynamically Typed (type declare नहीं); Platform Independent; Open Source (free)।
- Dynamically typed का क्या अर्थ है?Variable का type पहले declare नहीं करना पड़ता — value assign करते ही runtime पर type खुद तय होता है; एक ही variable बाद में दूसरे type की value रख सकता है।
- Tokens क्या हैं? इनके 5 types लिखिए।Program की सबसे छोटी इकाइयाँ। Types — Keywords (reserved words), Identifiers (नाम), Literals (fixed values), Operators (+, = आदि), Punctuators (( ) { } : आदि)।
- Identifier के rules लिखिए।Alphabet या _ से शुरू हो; digit से नहीं; special symbols (@#$%) नहीं; keyword नहीं हो सकता; case-sensitive होते हैं।
- Python में indentation का क्या महत्व है?Python में code blocks braces { } से नहीं, indentation (4 spaces) से बनते हैं — if/for/def के अंदर का code indent होना ज़रूरी; गलती पर IndentationError।
- Python में variable value को कैसे store करता है?Variable value का डिब्बा नहीं — memory (heap) में बने object का reference/label होता है। a = 10; b = a करने पर दोनों एक ही object को refer करते हैं (id() से proof)।
- Multiple assignment क्या है? उदाहरण दीजिए।एक line में कई variables को values देना — a, b, c = 1, 2, 3 (अलग-अलग) या x = y = z = 5 (same value)। Swap भी: a, b = b, a।
- Python के numeric data types उदाहरण सहित लिखिए।int (whole numbers, unlimited size — 10, -5), float (decimal — 3.14, 1.2e3), complex (real+imaginary — 2+3j)।
- 0.1 + 0.2 का output 0.3 क्यों नहीं आता?Computer numbers को binary में store करता है और 0.1 जैसी decimal values binary में exactly नहीं बनतीं — approximation से 0.30000000000000004 आता है। Fix: round() का उपयोग।
- Mutable और Immutable में अंतर उदाहरण सहित लिखिए।Immutable — value बदलने पर नया object बनता है, id() बदल जाती है (int, float, str, tuple, bool)। Mutable — वही object बदलता है, id() same रहती है (list, dict, set)।
- type() और isinstance() में अंतर बताइए।type() variable का exact type return करता है (<class 'int'>); isinstance(x, int) True/False बताता है और inheritance में ज़्यादा useful है।
- Implicit और Explicit type conversion समझाइए।Implicit — Python खुद करे (int + float → float)। Explicit — programmer खुद करे int(), float(), str(), bool() से; गलत conversion (int("abc")) पर ValueError।
- input() function की विशेषता व सावधानी लिखिए।input() user से जो भी ले, हमेशा string return करता है — numbers के लिए int(input()) या float(input()) से conversion ज़रूरी, वरना "5"+"5"="55" जैसी गलती।
- Python में Garbage Collection कैसे काम करता है?Python हर object का reference count रखता है — जितने variables उसे refer करते हैं। Count 0 होते ही (कोई refer नहीं कर रहा) Garbage Collector memory automatically free कर देता है।