⚠ यह कार्रवाई अनुमति नहीं है!
🐍 NIELIT O Level · M3-R5 Python · Hindi Notes

Chapter 3: Introduction to Python — Python की असली शुरुआत

अब algorithms से आगे — Python language खुद! इस chapter में Python का इतिहास व features, Tokens (Keywords, Identifiers, Literals), Variables का object-reference model, सभी Data Types (int, float, complex, bool, str, None), Mutable vs Immutable, Type Conversion और Input/Output — 35+ runnable examples के साथ, हर code में Copy button!

📑 15 Sections 💻 35+ Python Examples 📋 Copy Button ❓ 50 MCQs + Output Qs 🗓 Updated 2026
👉 सभी chapters देखने के लिए swipe करें
📑 Table of Contents — किसी भी topic पर सीधे जाएँ
3.0

Python क्या है? — History व आज का सबसे बड़ा नाम

Python एक high-level, interpreted, general-purpose programming language है जिसे Guido van Rossum ने 1991 में develop किया। नाम saanp से नहीं — comedy show "Monty Python's Flying Circus" से आया! उद्देश्य: programming को simple, readable व मज़ेदार बनाना।

📜 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 DevelopmentDjango, Flask frameworks से websites
Data ScienceData analysis, visualization (Pandas, NumPy)
AI / Machine LearningChatGPT जैसे AI models (TensorFlow, PyTorch)
AutomationBoring कामों को script से automatic करना
App / Game DevelopmentDesktop apps, simple games (Pygame)

🎉 आपका पहला Python Program

🐍 hello.py — programming की परंपरागत शुरुआत▶ Run
print("Hello World")
OUTPUTHello World
समझें: बस 1 line! C में यही करने के लिए 5-6 lines (#include, main(), return...) लगतीं। यही Python की simplicity है — सीधे काम की बात।
Exam Point: Python — Guido van Rossum, 1991, high-level + interpreted + general-purpose। नाम Monty Python show से। आज का version Python 3.x।
3.1

Features of Python — यह इतनी Popular क्यों है?

Python की popularity का राज़ इसके 10 features — exam में "Explain any 5 features of Python" लगभग पक्का question है!
#Featureमतलब
1Simple & Easy to LearnEnglish जैसा syntax — जल्दी सीखा जा सकता है
2High-LevelMemory management जैसी low-level details की चिंता नहीं
3InterpretedLine-by-line execution — debugging आसान
4Dynamically TypedData type declare करने की ज़रूरत नहीं
5Platform IndependentWindows/Linux/Mac — एक code सबपर चले
6Open Sourceबिल्कुल free — कोई भी use व modify कर सकता है
7Object-OrientedClass व object concepts को support करता है
8Large Standard Libraryहज़ारों ready-made libraries (math, random...)
9Extensible & EmbeddableC/C++ के साथ integrate हो सकता है
10PortableProgram एक system से दूसरे पर आसानी से जाए
🐍 Dynamic Typing की झलक▶ Run
x = 10          # x abhi integer hai
print(type(x))
x = "Hello"     # ab wahi x string ban gaya!
print(type(x))
OUTPUT<class 'int'>
<class 'str'>
Exam Point: Features में सबसे ज़्यादा पूछे जाने वाले — Interpreted, Dynamically Typed, Platform Independent, Open Source, Object-Oriented। "Python में variable declare क्यों नहीं करते?" → Dynamically Typed होने के कारण।
3.2

Interpreted व Dynamically Typed — दो सबसे बड़ी पहचान

Chapter 1 में हमने Compiler vs Interpreter व Static typing की theory पढ़ी थी — यहाँ देखते हैं Python में यह practically कैसा दिखता है।

⚡ 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 करना पड़ता है
Declarationx = 10 — बस!int x = 10;
Type बदलनाallowed — x = "Hello" चलेगाError देगा
Type checkRuntime परCompile time पर
🐍 एक ही variable, तीन रूप!▶ Run
data = 100        # int
print(data, type(data))
data = 3.14       # float
print(data, type(data))
data = "Python"   # string
print(data, type(data))
OUTPUT100 <class 'int'>
3.14 <class 'float'>
Python <class 'str'>
Exam Point: Python = Interpreted + Dynamically Typed। C/Java = Compiled + Statically Typed। Dynamic typing का फायदा — flexibility; नुकसान — type की गलतियाँ runtime पर ही पकड़ी जाती हैं।
3.3

Python Tokens — Program की सबसे छोटी इकाइयाँ

Tokens = Python program के सबसे छोटे units — जैसे वाक्य शब्दों से बनता है, program tokens से। 5 types: Keywords, Identifiers, Literals, Operators, Punctuators।

1️⃣ Keywords (Reserved Words)

Python के reserved words जिनका fixed meaning है — इन्हें variable नाम नहीं बना सकते। Case-sensitive हैं (True चलेगा, true नहीं)।

🐍 मुख्य Keywords (35 में से important)▶ Run
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
🐍 सारे keywords खुद देखिए▶ Run
import keyword
print(keyword.kwlist)
print("Total:", len(keyword.kwlist))
OUTPUT['False', 'None', 'True', 'and', 'as', ...]
Total: 35

2️⃣ Identifiers (नाम)

Variables, functions, classes को दिए गए नाम। Rules तोड़े तो SyntaxError!

Rule✔ Valid✘ Invalid
Alphabet या _ से शुरू होname, _age2num (digit से शुरू)
Digit से शुरू नहींnum22num
Special symbols नहीं (@#$%)total_markstotal@marks
Keyword नहीं हो सकताclass_nameclass
Case-sensitiveName व name अलग हैं
Naming Conventions (Best Practices): Meaningful नाम (total_marks, न कि tm); snake_case (my_variable_name); constants UPPERCASE (PI = 3.14)।

3️⃣ Literals (Fixed Values)

🐍 Code में सीधे लिखी values▶ Run
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

🐍 Operators काम करते हैं, Punctuators structure बनाते हैं▶ Run
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 में आएगी।)
Exam Point: Tokens के 5 types — Keywords, Identifiers, Literals, Operators, Punctuators। Python में 35 keywords। Identifier digit से शुरू नहीं हो सकता, keyword नहीं हो सकता, case-sensitive है।
3.4

Program Structure व Indentation — Python की सबसे अलग बात

दूसरी languages में code blocks { } से बनते हैं — 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()।
🐍 पूरा structure एक साथ▶ Run
# 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 bahar
OUTPUT (input: Aditya)Hello Aditya
Welcome!
Bye
🐍 गलत Indentation — Error!▶ Run
if True:
print("Hello")    # indentation nahi diya!
OUTPUTIndentationError: expected an indented block
Exam Point: Python blocks indentation से बनते हैं (standard: 4 spaces), braces { } से नहीं। गलत indentation पर IndentationError। हर statement नई line में; एक line में कई statements के लिए ; लगाना पड़ता है (पर अच्छी practice नहीं)।
3.5

Variables व Object References — Python का असली Model

Python में variable value को directly store नहीं करता — वह memory में बने object का reference (label/tag) होता है। जैसे किसी डिब्बे पर चिपका label — डिब्बा (object) memory में है, label (variable) उस पर लगा है!

Variable = Object पर लगा Label

a b 10 Object (memory में) "Hello" नया object a = 10; b = a → दोनों labels एक ही object (10) पर। बाद में a = "Hello" → a का label नए object पर shift!
🐍 Reference का proof — id() से▶ Run
a = 10
b = a           # b bhi USI object ko refer karta hai
print(id(a) == id(b))   # kya dono same object par hain?
OUTPUTTrue

🎁 Multiple Assignment — एक line में कई काम

🐍 तीन तरीके▶ Run
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)
OUTPUT1 2 3
5 5 5
20 10

🔒 Constants — Convention से

🐍 UPPERCASE = "इसे मत बदलो" का इशारा▶ Run
PI = 3.14
GRAVITY = 9.8
# Python me real constant keyword NAHI hota —
# technically value badal sakti hai, par programmer nahi badalta (convention)
Exam Point: Python में variable = object का reference (label), value का डिब्बा नहीं। id() से memory identity मिलती है। a, b = b, a = Pythonic swap। Constant के लिए कोई keyword नहीं — UPPERCASE naming convention है।
3.6

Data Types — हर Value की अपनी जाति

Data Type बताता है variable में किस तरह की value है और उस पर कौन-से operations हो सकते हैं। Python dynamically typed है — type खुद detect होता है।

📦 Built-in Data Types का नक्शा

CategoryTypesExample
Numericint, float, complex10, 3.14, 2+3j
BooleanboolTrue, False
Sequencestr, list, tuple"Hi", [1,2], (1,2)
Mappingdict{"a": 1}
Setset{1, 2, 3}
NoneNoneTypeNone
Note: list, tuple, dict, set की पूरी detail Chapter 5 (Sequence Data Types) में आएगी — यहाँ numeric, bool, str व None पर focus।

🔢 1. Numeric Types

🐍 int — whole numbers (unlimited size!)▶ Run
a = 10
b = -5
big = 99999999999999999999   # Python me koi limit nahi!
print(a, b, big)
OUTPUT10 -5 99999999999999999999
🐍 float — decimal व scientific notation▶ Run
x = 3.14
y = 1.2e3        # 1.2 × 10³ = 1200.0
print(x, y)
OUTPUT3.14 1200.0
🐍 complex — real + imaginary (j के साथ)▶ Run
z = 2 + 3j
print(z.real, z.imag)
OUTPUT2.0 3.0

🔢 Integer के अलग रूप — Binary, Octal, Hex

🐍 Prefix से number system बदलता है▶ Run
a = 0b1010    # Binary (base 2)
b = 0o12      # Octal (base 8)
c = 0xA       # Hexadecimal (base 16)
print(a, b, c)     # teeno = 10!
OUTPUT10 10 10

⚠️ Float Precision Issue — Exam का Famous Question

🐍 0.1 + 0.2 = 0.3 नहीं?!▶ Run
print(0.1 + 0.2)
print(round(0.1 + 0.2, 2))   # samadhan: round()
OUTPUT0.30000000000000004
0.3
ऐसा क्यों? Computer binary में सोचता है — जैसे हम 1/3 को exactly decimal में नहीं लिख सकते (0.333...), वैसे computer 0.1 को exactly binary में store नहीं कर सकता। इसीलिए तुलना करते समय round() का उपयोग करें।

✅ 2. Boolean — सिर्फ True या False

🐍 Conditions का आधार▶ Run
x = 10
print(x > 5)          # True
print(True + True)    # surprise! True = 1 hota hai
print(False * 10)     # False = 0
OUTPUTTrue
2
0

🔤 3. String — Characters का Sequence

🐍 Indexing व Slicing की झलक▶ Run
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
OUTPUTP
yth
Python 3
PythonPython
PYTHON
Note: String immutable है — name[0] = "J" करने पर TypeError आएगा! Strings की full detail (methods, slicing tricks) Chapter 5 में।

⬜ 4. NoneType — "कुछ नहीं" वाला Type

🐍 None ≠ 0, None ≠ ""▶ Run
x = None
print(x)
print(type(x))
print(x == 0)       # None zero NAHI hai!
OUTPUTNone
<class 'NoneType'>
False
Exam Point: int की size unlimited; 0b = binary, 0o = octal, 0x = hex; 0.1+0.2 ≠ 0.3 (binary approximation); True = 1, False = 0; String immutable; None ≠ 0 ≠ empty string — इसका type NoneType है।
3.7

Mutable vs Immutable — बदलेगा या नया बनेगा?

Immutable = value बदली नहीं जा सकती — बदलने पर नया object बनता है (int, float, str, tuple, bool)। Mutable = object वही रहता है, value अंदर ही बदल जाती है (list, dict, set)। Proof: id() function!
🐍 Immutable — id बदल गई (नया object)▶ Run
x = 10
print("Pehle:", id(x))
x = x + 5
print("Baad me:", id(x))   # ALAG id — naya object bana!
OUTPUTPehle: 140711234567890
Baad me: 140711234568050
← दोनों id अलग (आपके system पर numbers अलग होंगे)
🐍 Mutable — id वही रही (same object बदला)▶ Run
x = [1, 2, 3]
print("Pehle:", id(x))
x.append(4)
print("Baad me:", id(x))   # SAME id — wahi object badla!
print(x)
OUTPUTPehle: 140711234599999
Baad me: 140711234599999
[1, 2, 3, 4]
← id same रही
Immutable (नया object बनता है)Mutable (वही object बदलता है)
int, float, str, tuple, boollist, dict, set
Exam Point: "int/str/tuple immutable हैं, list/dict/set mutable" — यह classification MCQ में बार-बार आती है। पहचान का तरीका: modification के बाद id() same रही तो mutable, बदल गई तो immutable।
3.8

Type Checking व Conversion — Type जानना और बदलना

🔍 Type Checking — type() व isinstance()

🐍 दोनों functions की तुलना▶ Run
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?
OUTPUT<class 'int'>
True
False
अंतर: type() exact class बताता है; isinstance() हाँ/ना में जवाब देता है और inheritance में ज़्यादा useful है। Exam question: "type() vs isinstance()" — यही अंतर लिखना है।

🔄 Type Conversion के 2 तरीके

1️⃣ Implicit (Automatic) — Python खुद करे

🐍 int + float = float (खुद बना!)▶ Run
x = 10        # int
y = 2.5       # float
result = x + y
print(result, type(result))
OUTPUT12.5 <class 'float'>

2️⃣ Explicit (Manual) — Programmer खुद करे

🐍 int(), float(), str(), bool() से▶ Run
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 True
OUTPUT15 <class 'int'>
3.5
100%
False True
🐍 ⚠ गलत conversion = Error▶ Run
print(int("abc"))    # "abc" number nahi ban sakta!
OUTPUTValueError: invalid literal for int() with base 10: 'abc'
Exam Point: Implicit = Python खुद (int + float → float); Explicit = programmer खुद (int(), float(), str(), bool())। bool(0) = False, बाकी सब numbers True। int("abc") = ValueError।
3.9

Input व Output — User से बातचीत

सबसे बड़ा नियम: input() हमेशा STRING return करता है — number चाहिए तो int()/float() से convert करना ही पड़ेगा! और output के लिए print() के 3 अंदाज़: comma, f-string, sep/end।
🐍 input() का string trap▶ Run
age = input("Enter age: ")     # user ne 20 dala
print(age + 5)                  # ERROR aayega!
OUTPUTTypeError: can only concatenate str (not "int") to str
← "20" string है, उसमें 5 नहीं जुड़ सकता!
🐍 सही तरीका — conversion के साथ▶ Run
age = int(input("Enter age: "))
print("5 saal baad aap", age + 5, "ke honge")
OUTPUT (input: 20)5 saal baad aap 25 ke honge

🖨️ print() के तरीके

🐍 f-string — सबसे modern तरीका▶ Run
name = "Rahul"
marks = 92
print(f"My name is {name} and I scored {marks}%")
print(f"Half marks = {marks / 2}")    # andar calculation bhi!
OUTPUTMy name is Rahul and I scored 92%
Half marks = 46.0
🐍 sep व end — print को customize करना▶ Run
print("Boosting", "Skills", sep="-")
print("Hello", end=" ")
print("World")     # nayi line nahi mili, saath chhapa
OUTPUTBoosting-Skills
Hello World
Exam Point: input() हमेशा string देता है — int(input()) पैटर्न याद रखें। print() में sep (शब्दों के बीच) व end (line के अंत में) parameters; f-string में {} के अंदर variables व calculations दोनों चलते हैं।
3.10

Memory Management व Garbage Collection — सफाई अपने आप

C में programmer खुद memory allocate/free करता है — Python में सब automatic! Objects heap memory में बनते हैं, और जो object कोई use नहीं कर रहा उसे Garbage Collector खुद हटा देता है।

🧠 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!
🐍 Garbage Collection in action▶ Run
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)
OUTPUTNone
Exam Point: Python में memory management automatic; objects heap में; Garbage Collection reference counting पर आधारित — count 0 = memory free। Programmer को manually memory manage नहीं करनी पड़ती (C से बड़ा अंतर)।
3.11

🎯 Output-Based Questions — इस Chapter के Topics से

ये सभी questions इसी chapter के concepts (types, conversion, input, string basics, id) से हैं — loops/conditions वाले questions Chapter 2 में हो चुके। पहले खुद सोचिए!

Q1. type() की पहचान

🐍 Output बताइए▶ Run
print(type(10/2))
print(type(10//2))
ANSWER<class 'float'>
<class 'int'>
← / हमेशा float देता है (5.0), // integer (5)।

Q2. input() का String खेल

🐍 User दोनों बार 5 डालता है — output?▶ Run
a = input()
b = input()
print(a + b)
ANSWER55
← input() strings देता है — "5" + "5" = "55" (concatenation, जोड़ नहीं!)।

Q3. Boolean की Math

🐍 Output बताइए▶ Run
print(True + True + False)
print(True * 5)
ANSWER2
5
← True = 1, False = 0 — इसलिए 1+1+0 = 2 और 1×5 = 5।

Q4. String Indexing

🐍 Output बताइए▶ Run
s = "BOOSTING"
print(s[0], s[3])
print(s[2:5])
print(s[-1])
ANSWERB S
OST
G
← Index 0 से; s[2:5] = index 2,3,4; s[-1] = आखिरी character।

Q5. Number Systems

🐍 Output बताइए▶ Run
print(0b101 + 0o10 + 0x10)
ANSWER29
← 0b101 = 5, 0o10 = 8, 0x10 = 16 → 5+8+16 = 29।

Q6. Type Conversion Chain

🐍 Output बताइए▶ Run
x = "7"
y = int(x) + float(x)
print(y, type(y))
ANSWER14.0 <class 'float'>
← 7 + 7.0 = int + float → implicit conversion से float।

Q7. Immutability का Error

🐍 क्या होगा?▶ Run
name = "Python"
name[0] = "J"
print(name)
ANSWERTypeError: 'str' object does not support item assignment
← String immutable है — किसी index पर value assign नहीं कर सकते।

Q8. Multiple Assignment

🐍 Output बताइए▶ Run
a, b, c = 5, 10, 15
a, c = c, a
print(a, b, c)
ANSWER15 10 5
← a और c swap हुए, b वहीं रहा।

Q9. f-string के अंदर Calculation

🐍 Output बताइए▶ Run
x = 4
print(f"Square of {x} is {x ** 2}")
ANSWERSquare of 4 is 16
← f-string के {} में expressions भी evaluate होते हैं।

Q10. None की तुलना

🐍 Output बताइए▶ Run
x = None
print(x == 0)
print(x == "")
print(x == None)
ANSWERFalse
False
True
← None सिर्फ None के बराबर है — न 0 के, न empty string के।

Q11. Identifier Valid या Invalid?

🐍 कौन-सी lines error देंगी?▶ Run
_name = "A"      # Line 1
2marks = 50      # Line 2
total_marks = 90 # Line 3
class = "10th"   # Line 4
ANSWERLine 2 (digit से शुरू) और Line 4 (class एक keyword है) — दोनों SyntaxError देंगी। Line 1 व 3 बिल्कुल valid।

Q12. sep और end का Combo

🐍 Output बताइए▶ Run
print("A", "B", sep="*", end="#")
print("C")
ANSWERA*B#C
← sep="*" ने A-B के बीच * लगाया; end="#" ने newline की जगह # — इसलिए C उसी line में।
3.12

💻 Practice Programs — Chapter 3 के Concepts पर

Programs इसी chapter के concepts (input conversion, f-string, type functions, number systems) पर — Chapter 2 वाले loops/logic programs से बिल्कुल अलग।

Program 1 — Student Introduction Card (f-string)

🐍 intro_card.py▶ Run
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}")
OUTPUT (inputs: Rahul, 17, Lucknow)--- Student Card ---
Naam : Rahul
Age : 17 saal (next year: 18)
City : Lucknow

Program 2 — Marks Percentage Calculator

🐍 percentage.py — float conversion का उपयोग▶ Run
obtained = float(input("Obtained marks: "))
total = float(input("Total marks: "))
percent = (obtained / total) * 100
print(f"Percentage = {round(percent, 2)}%")
OUTPUT (inputs: 432, 500)Percentage = 86.4%

Program 3 — Type Explorer

🐍 type_explorer.py — हर value का type पहचानो▶ Run
values = [10, 3.14, "Hello", True, None, 2+3j]
for v in values:
    print(v, "->", type(v))
OUTPUT10 -> <class 'int'>
3.14 -> <class 'float'>
Hello -> <class 'str'>
True -> <class 'bool'>
None -> <class 'NoneType'>
(2+3j) -> <class 'complex'>

Program 4 — Number System Converter

🐍 converter.py — bin(), oct(), hex()▶ Run
n = int(input("Decimal number: "))
print(f"Binary      : {bin(n)}")
print(f"Octal       : {oct(n)}")
print(f"Hexadecimal : {hex(n)}")
OUTPUT (input: 25)Binary : 0b11001
Octal : 0o31
Hexadecimal : 0x19

Program 5 — KM to Miles Converter

🐍 km_miles.py — constant का उपयोग▶ Run
CONVERSION_FACTOR = 0.621371    # constant (UPPERCASE)
km = float(input("Kilometers: "))
miles = km * CONVERSION_FACTOR
print(f"{km} km = {round(miles, 2)} miles")
OUTPUT (input: 100)100.0 km = 62.14 miles

Program 6 — String Playground

🐍 string_play.py — methods की practice▶ Run
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]}")
OUTPUT (input: Boosting)Uppercase : BOOSTING
Lowercase : boosting
Length : 8 characters
Pehla : B | Aakhri: g

Program 7 — Currency Note Value (bool as number)

🐍 bool_magic.py — True/False से गिनती▶ Run
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)
OUTPUT20 se bade numbers: 2
← False + True + True = 0+1+1 = 2 — boolean की math!

Program 8 — Simple Bill with Type Conversion

🐍 bill.py — सब कुछ एक साथ▶ Run
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)}")
OUTPUT (inputs: Pen, 12.5, 4)--- BILL ---
Pen x 4 = Rs. 50.0
GST (18%) = Rs. 9.0
Grand Total = Rs. 59.0
Exam Point: int(input()), float(input()), f-string formatting, round(), bin()/oct()/hex() — ये पाँचों patterns practical exam में सीधे काम आते हैं।
3.13

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)।
3.14

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)

  1. Python क्या है? इसे किसने और कब बनाया?Python एक high-level, interpreted, general-purpose language है — Guido van Rossum ने 1991 में बनाई। नाम Monty Python comedy show से आया।
  2. Python के कोई 5 features लिखिए।Simple व Easy to Learn; Interpreted (line-by-line); Dynamically Typed (type declare नहीं); Platform Independent; Open Source (free)।
  3. Dynamically typed का क्या अर्थ है?Variable का type पहले declare नहीं करना पड़ता — value assign करते ही runtime पर type खुद तय होता है; एक ही variable बाद में दूसरे type की value रख सकता है।
  4. Tokens क्या हैं? इनके 5 types लिखिए।Program की सबसे छोटी इकाइयाँ। Types — Keywords (reserved words), Identifiers (नाम), Literals (fixed values), Operators (+, = आदि), Punctuators (( ) { } : आदि)।
  5. Identifier के rules लिखिए।Alphabet या _ से शुरू हो; digit से नहीं; special symbols (@#$%) नहीं; keyword नहीं हो सकता; case-sensitive होते हैं।
  6. Python में indentation का क्या महत्व है?Python में code blocks braces { } से नहीं, indentation (4 spaces) से बनते हैं — if/for/def के अंदर का code indent होना ज़रूरी; गलती पर IndentationError।
  7. Python में variable value को कैसे store करता है?Variable value का डिब्बा नहीं — memory (heap) में बने object का reference/label होता है। a = 10; b = a करने पर दोनों एक ही object को refer करते हैं (id() से proof)।
  8. Multiple assignment क्या है? उदाहरण दीजिए।एक line में कई variables को values देना — a, b, c = 1, 2, 3 (अलग-अलग) या x = y = z = 5 (same value)। Swap भी: a, b = b, a।
  9. Python के numeric data types उदाहरण सहित लिखिए।int (whole numbers, unlimited size — 10, -5), float (decimal — 3.14, 1.2e3), complex (real+imaginary — 2+3j)।
  10. 0.1 + 0.2 का output 0.3 क्यों नहीं आता?Computer numbers को binary में store करता है और 0.1 जैसी decimal values binary में exactly नहीं बनतीं — approximation से 0.30000000000000004 आता है। Fix: round() का उपयोग।
  11. Mutable और Immutable में अंतर उदाहरण सहित लिखिए।Immutable — value बदलने पर नया object बनता है, id() बदल जाती है (int, float, str, tuple, bool)। Mutable — वही object बदलता है, id() same रहती है (list, dict, set)।
  12. type() और isinstance() में अंतर बताइए।type() variable का exact type return करता है (<class 'int'>); isinstance(x, int) True/False बताता है और inheritance में ज़्यादा useful है।
  13. Implicit और Explicit type conversion समझाइए।Implicit — Python खुद करे (int + float → float)। Explicit — programmer खुद करे int(), float(), str(), bool() से; गलत conversion (int("abc")) पर ValueError।
  14. input() function की विशेषता व सावधानी लिखिए।input() user से जो भी ले, हमेशा string return करता है — numbers के लिए int(input()) या float(input()) से conversion ज़रूरी, वरना "5"+"5"="55" जैसी गलती।
  15. Python में Garbage Collection कैसे काम करता है?Python हर object का reference count रखता है — जितने variables उसे refer करते हैं। Count 0 होते ही (कोई refer नहीं कर रहा) Garbage Collector memory automatically free कर देता है।
Revision Tip: Guido/1991, 35 keywords, identifier rules, immutable list (int/float/str/tuple/bool), input() = string, True = 1 — ये 6 facts इस chapter के आधे MCQs cover कर देते हैं। Section 3.11 के output questions ज़रूर दोहराएँ!
FAQ

अक्सर पूछे जाने वाले प्रश्न

Python क्या है और इसे किसने बनाया?
Python एक high-level, interpreted, general-purpose programming language है जिसे Guido van Rossum ने 1991 में develop किया। इसका syntax English जैसा simple है, इसीलिए beginners के लिए सबसे popular language है। उपयोग — Web Development, Data Science, AI/ML, Automation।
Python dynamically typed language का क्या मतलब है?
Variable का data type पहले से declare नहीं करना पड़ता — value assign करते ही Python runtime पर type खुद decide कर लेता है। एक ही variable पहले int (x = 10), फिर string (x = "Hello") रख सकता है।
Keywords और Identifiers में क्या अंतर है?
Keywords Python के reserved words हैं जिनका fixed meaning है (if, else, for, while, def...) — इन्हें variable नाम नहीं बना सकते। Identifiers programmer द्वारा दिए गए नाम हैं (variables, functions के) — alphabet/underscore से शुरू हों, digit से नहीं, case-sensitive।
input() function हमेशा string क्यों return करता है?
Python का input() user से जो भी लेता है उसे string मानता है — number चाहिए तो int(input()) या float(input()) से explicit conversion करना ज़रूरी है, वरना "10" + "20" = "1020" जैसी गलती होगी।
Mutable और Immutable data types कौन-से हैं?
Immutable (value change नहीं होती, नया object बनता है) — int, float, str, tuple, bool। Mutable (object वही रहता है, value बदल जाती है) — list, dict, set। id() function से यह अंतर देखा जा सकता है।
None (NoneType) क्या है?
None एक special constant है जो "कोई value नहीं" दर्शाता है — इसका data type NoneType है। जब variable को अभी value assign नहीं करनी हो या function कुछ return न करे, तब None उपयोग होता है। None ≠ 0 और None ≠ empty string।

🎯 Chapter 3 पूरा हुआ! अब आगे बढ़ें

Chapter 4 में Operators की पूरी दुनिया — Arithmetic, Relational, Logical, Bitwise, Assignment व operator precedence।

Chapter 4 पढ़ें ➜