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

Chapter 5: Sequence Data Types — List, Tuple, Dictionary, Set

Python के सबसे उपयोगी data structures — List (mutable), Tuple (immutable), Dictionary (key-value) और Set (unique elements)! Indexing, Slicing, String के 15+ Methods, हर collection के पूरे Methods (extend, count, update, add, discard...) व Mutability — हर concept को diagrams से visualize किया गया है, साथ में 60+ examples

📑 12 Sections 🖼️ 6 Diagrams 💻 60+ Examples ❓ 50 MCQs + Output Qs 🗓 Updated 2026
👉 सभी chapters देखने के लिए swipe करें
📑 Table of Contents — किसी भी topic पर सीधे जाएँ
5.0

Sequence Data Types क्या हैं? — Ordered Collections का परिवार

Sequence = items का ordered collection जहाँ हर item का एक index होता है। जैसे किसी train में बोगियाँ क्रम से लगी हों — हर बोगी की एक seat number। String, List, Tuple, Range — सब sequences हैं।

🗂️ Python के मुख्य Collection Data Types

TypeSyntaxOrdered?Mutable?Duplicates?
String"text"✔ हाँ✘ नहीं✔ हाँ
List[ ]✔ हाँ✔ हाँ✔ हाँ
Tuple( )✔ हाँ✘ नहीं✔ हाँ
Dictionary{key: value}✔ (3.7+)✔ हाँ✘ keys unique
Set{ }✘ नहीं✔ हाँ✘ नहीं
याद रखने की trick: [ ] List = बदल सकते हो; ( ) Tuple = tight/locked, नहीं बदल सकते; {key:value} Dictionary = मतलब वाली जोड़ी; { } Set = अनोखे (unique) सामान की टोकरी।
Exam Point: Ordered vs Unordered — List/Tuple/Dict(3.7+) ordered हैं, Set unordered। Mutable — List, Dict, Set; Immutable — String, Tuple।
5.1

Indexing व Slicing — एक item या टुकड़ा निकालना

Indexing = एक element निकालना (sequence[index])। Slicing = हिस्सा निकालना (sequence[start:stop:step])। Index हमेशा 0 से शुरू; negative index पीछे से गिनती करता है।

Indexing — Positive व Negative दोनों दिशा से

P Y T H O N 012345 -6-5-4-3-2-1 हरा = आगे से गिनती (0 से); लाल = पीछे से गिनती (-1 से)
🐍 Positive व Negative Indexing▶ Run
name = "PYTHON"
print(name[0])    # P (pehla)
print(name[3])    # H (chautha)
print(name[-1])   # N (aakhri)
print(name[-3])   # T (peeche se teesra)
OUTPUTP
H
N
T

Slicing [start:stop:step] — stop हमेशा excluded!

P Y T H O N 012345 text[1:4] → "YTH" (orange highlighted) index 4 (O) शामिल नहीं — stop हमेशा exclude होता है
🐍 Slicing के सभी patterns▶ Run
text = "PYTHON"
print(text[1:4])    # YTH  (index 1,2,3)
print(text[:3])     # PYT  (shuru se index 2 tak)
print(text[2:])     # THON (index 2 se aakhir tak)
print(text[::2])    # PTO  (har 2nd character)
print(text[::-1])   # NOHTYP (poori ulti!)
OUTPUTYTH
PYT
THON
PTO
NOHTYP
Exam Point: Slicing हमेशा नया sequence return करती है, original नहीं बदलती। [::−1] = reverse trick सबसे ज़्यादा exam में पूछी जाती है। start default 0, stop default end तक, step default 1।

🔤 String Methods — पूरी List (Exam में बहुत पूछे जाते हैं)

String एक sequence type है — इसलिए इंडेक्सिंग/स्लाइसिंग तो होती ही है, साथ में 30+ built-in methods भी मिलते हैं। हर method string को immutable रखते हुए नई string return करता है — original कभी नहीं बदलती।
MethodकामExample
upper()सभी अक्षर CAPITAL"hi".upper() → "HI"
lower()सभी अक्षर छोटे"HI".lower() → "hi"
title()हर शब्द का पहला अक्षर Capital"hello world".title() → "Hello World"
capitalize()सिर्फ पहला अक्षर Capital"hello".capitalize() → "Hello"
strip()शुरू व अंत की whitespace हटाना" hi ".strip() → "hi"
lstrip() / rstrip()सिर्फ बाएँ / सिर्फ दाएँ की whitespace" hi".lstrip() → "hi"
split(sep)String को list में तोड़ना"a,b,c".split(",") → ['a','b','c']
join(list)List को string में जोड़ना (उल्टा split)"-".join(['a','b']) → "a-b"
replace(old,new)Substring बदलना"cat".replace("c","b") → "bat"
find(sub)पहली मिलान की index (न मिले तो -1)"hello".find("l") → 2
count(sub)Substring कितनी बार आया"hello".count("l") → 2
startswith() / endswith()शुरुआत/अंत जाँचना (True/False)"hello".startswith("he") → True
isalpha() / isdigit() / isalnum()सिर्फ letters / सिर्फ digits / दोनों जाँचना"abc".isalpha() → True
len(string)Length (built-in function, method नहीं)len("hello") → 5
🐍 Case Conversion Methods▶ Run
s = "python programming"
print(s.upper())
print(s.title())
print(s.capitalize())
OUTPUTPYTHON PROGRAMMING
Python Programming
Python programming
🐍 strip() — Extra Spaces हटाना (User Input में बहुत काम आता है)▶ Run
name = "   Aditya   "
print("[" + name + "]")           # spaces ke saath
print("[" + name.strip() + "]")   # saaf ho gaya
OUTPUT[ Aditya ]
[Aditya]
🐍 split() व join() — एक-दूसरे के उल्टे▶ Run
sentence = "Python is fun"
words = sentence.split()          # space se todna
print(words)

joined = "-".join(words)          # "-" se wapas jodna
print(joined)

csv_line = "Ravi,20,Lucknow"
fields = csv_line.split(",")
print(fields)
OUTPUT['Python', 'is', 'fun']
Python-is-fun
['Ravi', '20', 'Lucknow']
🐍 replace(), find(), count()▶ Run
msg = "I like Java. Java is good."
print(msg.replace("Java", "Python"))   # sab jagah badla
print(msg.find("Java"))                 # pehli baar kahan mila
print(msg.count("Java"))                # kitni baar aaya
OUTPUTI like Python. Python is good.
7
2
🐍 startswith(), endswith() व isalpha()/isdigit()▶ Run
filename = "report.pdf"
print(filename.startswith("report"))   # True
print(filename.endswith(".pdf"))       # True

print("Python3".isalpha())    # False - '3' digit hai
print("12345".isdigit())      # True
print("Python3".isalnum())    # True - letters+digits dono chalte hain
OUTPUTTrue
True
False
True
True
याद रखें: String के सभी methods नई string return करते हैं, original को कभी नहीं बदलते (immutable!) — इसलिए s.upper() लिखने भर से s नहीं बदलता, result को किसी variable में रखना पड़ता है: s = s.upper()
Exam Point: upper()/lower()/title()/capitalize() — case बदलने वाले; strip() whitespace हटाता है; split()/join() एक-दूसरे के उल्टे काम करते हैं; find() न मिलने पर -1 देता है (Error नहीं); count() occurrences गिनता है; isalpha()/isdigit()/isalnum() — बूलियन जाँच। सभी methods नई string देते हैं, original नहीं बदलती।
5.2

Lists — सबसे Powerful, हमेशा बदल सकते हैं

List = [ ] में लिखा ordered, mutable, heterogeneous collection। सबसे ज़्यादा उपयोग होने वाला data structure — duplicate values allowed, कोई भी data type mix कर सकते हैं।
🐍 List बनाना — 4 तरीके▶ Run
empty = []
numbers = [1, 2, 3, 4]
mixed = [10, "Python", 3.14, True]     # kai types ek saath!
nested = [[1, 2], [3, 4]]               # list ke andar list

✏️ List Modify करना — Add, Update, Remove

🐍 append, insert, remove, pop▶ Run
nums = [10, 20, 30]
nums[1] = 99          # update — index se
nums.append(40)       # end me add
nums.insert(1, 15)    # position 1 par insert
print(nums)

nums.remove(99)       # value se hataya
nums.pop()            # aakhri element hataya
print(nums)
OUTPUT[10, 15, 99, 30, 40]
[10, 15, 30]

📋 Common List Methods

Methodकाम
append(x)अंत में एक element जोड़ना
insert(i, x)index i पर element डालना
remove(x)value से हटाना (पहला मिलान)
pop(i)index से हटाना (default: last)
sort()ascending order (in-place)
reverse()क्रम उल्टा करना
clear()सब कुछ खाली करना
extend(iterable)एक साथ कई elements जोड़ना (list/tuple से)
count(x)x कितनी बार list में है, गिनना
index(x)x की पहली index पता करना
copy()List की नई (independent) copy बनाना
🐍 append() vs extend() — बड़ा अंतर!▶ Run
a = [1, 2, 3]
b = [1, 2, 3]

a.append([4, 5])    # POORI list ek hi element ban kar judi
b.extend([4, 5])    # dono elements ALAG-ALAG jude

print("append:", a)
print("extend:", b)
OUTPUTappend: [1, 2, 3, [4, 5]]
extend: [1, 2, 3, 4, 5]
समझें: append() पूरी list को एक ही (nested) element की तरह जोड़ता है — 4 elements की जगह अंत में एक sub-list जुड़ी। extend() हर element को अलग-अलग list में मिला देता है — यही exam का classic difference-question है!
🐍 count(), index() व copy()▶ Run
nums = [10, 20, 30, 20, 40, 20]
print(nums.count(20))    # 20 kitni baar hai
print(nums.index(30))    # 30 ki pehli index

safe_copy = nums.copy()
safe_copy.append(99)
print("Original:", nums)      # sanrakshit rahi!
print("Copy:", safe_copy)
OUTPUT3
2
Original: [10, 20, 30, 20, 40, 20]
Copy: [10, 20, 30, 20, 40, 20, 99]
Exam Point: extend() individual elements जोड़ता है (append() पूरी चीज़ को एक element की तरह); count() occurrences गिनता है; index() पहली मिलान की position; copy() = a[:] जैसा — independent नई list (Section 5.6 के aliasing problem से बचने के लिए)।
🐍 sort, reverse, len/max/min/sum▶ Run
marks = [78, 92, 65, 88, 55]
marks.sort()
print("Sorted:", marks)
print("Length:", len(marks))
print("Max:", max(marks), "| Min:", min(marks))
print("Average:", sum(marks) / len(marks))
OUTPUTSorted: [55, 65, 78, 88, 92]
Length: 5
Max: 92 | Min: 55
Average: 75.6

📦 List Comprehension — Python का जादू

🐍 एक line में नई list बनाना▶ Run
nums = [1, 2, 3, 4, 5]
squares = [n * n for n in nums]           # har n ka square
evens = [n for n in nums if n % 2 == 0]   # sirf even
print(squares)
print(evens)
OUTPUT[1, 4, 9, 16, 25]
[2, 4]
Exam Point: List mutable, [ ] में, duplicates allowed, mixed types allowed। remove() value से, pop() index से हटाता है। List comprehension syntax: [expression for item in sequence if condition]।
5.3

Tuples — एक बार बना, हमेशा के लिए Lock

Tuple = ( ) में लिखा ordered, immutable collection। List जैसा दिखता है पर एक बार बनने के बाद बदल नहीं सकता — इसीलिए list से तेज़ व कम memory लेता है।
🐍 Tuple बनाना — Single element का trick!▶ Run
t1 = (1, 2, 3)
t2 = (10, "Python", 3.14)
single = (5,)       # COMMA zaroori hai! bina comma yah int hai
not_tuple = (5)     # yah sirf int 5 hai, tuple nahi!
print(type(single), type(not_tuple))
OUTPUT<class 'tuple'> <class 'int'>
बड़ी गलती से बचें: (5) tuple नहीं है, सिर्फ number 5 है (bracket को math जैसा लिया)! Single-element tuple के लिए comma ज़रूरी: (5,)

🔒 List vs Tuple — पूरी तुलना

आधारListTuple
Syntax[ ]( )
MutabilityMutableImmutable
Speedधीमीतेज़
Memoryज़्यादाकम
Methodsबहुत सारेसिर्फ count(), index()
कब उपयोग करेंData बदलेगाData constant रहेगा

🔢 Tuple के 2 Methods — count() व index()

🐍 Tuple के दोनों methods उपयोग में▶ Run
marks = (78, 92, 78, 65, 78, 88)
print(marks.count(78))    # 78 kitni baar hai
print(marks.index(92))    # 92 ki pehli index
OUTPUT3
1
समझें: List की तरह Tuple में भी count() व index() काम करते हैं — बस tuple में modify करने वाला कोई method नहीं है (append, remove जैसा कुछ नहीं) क्योंकि tuple immutable है।

📦 Tuple Unpacking — एक साथ कई variables

🐍 Elegant तरीका▶ Run
student = ("Aditya", 20, "Lucknow")
name, age, city = student      # unpacking!
print(f"{name} rehte hain {city} me, age {age}")
OUTPUTAditya rehte hain Lucknow me, age 20
Exam Point: (5,) tuple, (5) सिर्फ int — comma ही tuple बनाता है, brackets नहीं। Tuple के सिर्फ 2 methods: count() व index()। Tuple immutable होने से dictionary की key बन सकता है, list नहीं!
5.4

Dictionaries — Key से Value ढूँढो

Dictionary = {key: value} pairs की collection। Index number नहीं, key से access होती है — जैसे असली dictionary में शब्द (key) से meaning (value) ढूँढते हैं। Keys unique व immutable होनी चाहिए।

Dictionary — Key ➜ Value Mapping

"name" "age" "course" "Amit" 20 "Python" KEY (नीला) → VALUE (हरा)
🐍 Dictionary बनाना व access करना▶ Run
student = {"name": "Amit", "age": 20, "course": "Python"}
print(student["name"])       # direct access
print(student.get("age"))    # safe access (error nahi dega)
print(student.get("city", "N/A"))   # default value agar key nahi mili
OUTPUTAmit
20
N/A

✍️ Add, Update, Remove

🐍 Dictionary modify करना▶ Run
d = {"name": "Amit", "age": 20}
d["course"] = "Python"    # naya key-value add
d["age"] = 21              # existing update
print(d)
d.pop("age")               # key hataya
print(d)
OUTPUT{'name': 'Amit', 'age': 21, 'course': 'Python'}
{'name': 'Amit', 'course': 'Python'}

📋 Dictionary के बाकी महत्वपूर्ण Methods

Methodकाम
keys()सभी keys की view देना
values()सभी values की view देना
items()सभी key-value pairs की view देना
update(other_dict)दूसरी dictionary से values merge करना
setdefault(key, default)key हो तो value दो, न हो तो default डालकर दो
popitem()आख़िरी जोड़ा हुआ key-value हटाना
🐍 keys() व values() — अलग-अलग निकालना▶ Run
student = {"name": "Amit", "age": 20, "course": "Python"}
print(list(student.keys()))
print(list(student.values()))
OUTPUT['name', 'age', 'course']
['Amit', 20, 'Python']
🐍 update() — दो dictionaries merge करना▶ Run
d1 = {"name": "Amit", "age": 20}
d2 = {"age": 21, "city": "Lucknow"}   # age common hai
d1.update(d2)
print(d1)
OUTPUT{'name': 'Amit', 'age': 21, 'city': 'Lucknow'}
← age overwrite हो गई (d2 वाली value जीती), city नई जुड़ी।
🐍 setdefault() व popitem()▶ Run
d = {"name": "Amit"}
d.setdefault("age", 18)     # "age" nahi thi -> 18 daal di
d.setdefault("name", 99)    # "name" pehle se hai -> nahi badli
print(d)

d.popitem()                  # aakhri jodi hatai
print(d)
OUTPUT{'name': 'Amit', 'age': 18}
{'name': 'Amit'}
Exam Point: keys()/values()/items() — तीनों "view" objects देते हैं (list() से list बना सकते हैं); update() दूसरी dict से merge करता है (common keys overwrite होती हैं); setdefault() सिर्फ तभी value डालता है जब key न हो; popitem() हमेशा सबसे आख़िरी जोड़ा हुआ pair हटाता है।
5.5

Sets — Unique Items की टोकरी

Set = { } में unordered, mutable collection जिसमें duplicate values नहीं होतीं। Mathematical set operations (Union, Intersection, Difference) के लिए बना है।
🐍 Duplicates अपने आप गायब!▶ Run
nums = [1, 2, 2, 3, 3, 3, 4]
unique = set(nums)
print(unique)

empty = set()   # NOTE: {} khaali dictionary hai, set nahi!
OUTPUT{1, 2, 3, 4}

Set Operations — Venn Diagrams

A | B (Union) A & B (Intersection) A − B (Difference) A ^ B (Symmetric Diff)
🐍 चारों operations एक साथ▶ Run
A = {1, 2, 3, 4}
B = {3, 4, 5, 6}
print("Union      :", A | B)   # sab kuch dono se
print("Intersection:", A & B)  # sirf common
print("Difference :", A - B)   # A me hai, B me nahi
print("Symmetric  :", A ^ B)   # dono me alag-alag jo hai
OUTPUTUnion : {1, 2, 3, 4, 5, 6}
Intersection: {3, 4}
Difference : {1, 2}
Symmetric : {1, 2, 5, 6}

✏️ Set Modify करने के Methods

Methodकाम
add(x)एक element जोड़ना
remove(x)Element हटाना (न मिले तो KeyError)
discard(x)Element हटाना (न मिले तो कोई error नहीं — safe)
clear()पूरा set खाली करना
union() / intersection() / difference()| , & , − के ही method-रूप (union(), intersection() आदि)
🐍 add(), remove() व discard() का अंतर▶ Run
fruits = {"apple", "mango"}
fruits.add("banana")
print(fruits)

fruits.discard("grape")   # grape hai hi nahi — koi error nahi!
print("discard() ke baad bhi safe:", fruits)

# fruits.remove("grape")  # yah ERROR degi — KeyError!
OUTPUT{'apple', 'mango', 'banana'}
discard() ke baad bhi safe: {'apple', 'mango', 'banana'}
🐍 Operators व Methods दोनों एक जैसा काम करते हैं▶ Run
A = {1, 2, 3}
B = {2, 3, 4}

print(A.union(B))          # same as A | B
print(A.intersection(B))   # same as A & B
print(A.difference(B))     # same as A - B
OUTPUT{1, 2, 3, 4}
{2, 3}
{1}
Exam Point: set() खाली set बनाता है, {} खाली dictionary! remove() न मिलने पर KeyError, discard() safe है (कोई error नहीं)। Union/Intersection/Difference operators (|, &, −) और methods (union(), intersection(), difference()) — दोनों एक जैसा result देते हैं, बस syntax अलग। Set indexing/slicing support नहीं करता (unordered है)।
5.6

Mutability — बदलेगा या नया बनेगा? (Recap + Deep Dive)

Chapter 3 में हमने mutable/immutable की बुनियाद देखी थी — अब सभी sequence types पर लागू करते हैं। id() function से जाँच: modify करने पर id() same रहे तो mutable, बदल जाए तो immutable।

List (Mutable) vs Tuple (Immutable) — Memory में क्या होता है

LIST — mutable (id() same रहती है) id: 5001 [10, 20, 30] id: 5001 (SAME!) [10, 20, 30, 40] append(40) के बाद — वही object बदल गया TUPLE जैसा STRING — immutable (नई id!) id: 7001 "Python" id: 7002 (नया!) "Python3" += के बाद — पुराना छोड़, नया object बना
🐍 id() से खुद जाँचिए▶ Run
nums = [10, 20, 30]
print("List id before:", id(nums))
nums.append(40)
print("List id after :", id(nums))    # SAME

text = "Python"
print("Str id before:", id(text))
text = text + "3"
print("Str id after :", id(text))     # ALAG
OUTPUTList id before: 140234567800
List id after : 140234567800 (same!)
Str id before: 140234598200
Str id after : 140234598350 (नई!)

🧩 Interesting: Tuple के अंदर List — मिश्रित behavior

🐍 Tuple immutable, पर अंदर की list mutable!▶ Run
t = (1, [2, 3], 4)
t[1].append(99)      # tuple ka element BADLA nahi, list ke ANDAR add hua
print(t)
# t[0] = 100         # yah error dega — tuple ke direct elements immutable hain
OUTPUT(1, [2, 3, 99], 4)
Exam Point: Mutable: list, dict, set (id() same रहती है modify करने पर)। Immutable: str, tuple, int, float (id() बदल जाती है)। Tuple के अंदर mutable object (जैसे list) हो तो उसके अंदर बदलाव हो सकता है — पर tuple के elements सीधे बदल नहीं सकते।
5.7

🎯 Output-Based Questions — List, Tuple, Dict, Set पर

इस chapter के concepts पर 12 tricky questions — पहले खुद सोचिए!

Q1. Negative Indexing

🐍 Output बताइए▶ Run
lst = [10, 20, 30, 40, 50]
print(lst[-2])
print(lst[1:-1])
ANSWER40
[20, 30, 40]
← -2 पीछे से दूसरा; slicing में -1 आखिरी को exclude करता है।

Q2. List की Aliasing (साझा Reference)

🐍 Output बताइए▶ Run
a = [1, 2, 3]
b = a
b.append(4)
print(a)
ANSWER[1, 2, 3, 4]
← b = a से दोनों एक ही object को refer करते हैं — b बदला तो a भी बदल गया!

Q3. Tuple Single Element Trap

🐍 Output बताइए▶ Run
t = (10)
print(type(t))
ANSWER<class 'int'>
← comma नहीं है, इसलिए यह tuple नहीं — साधारण int!

Q4. Dictionary get() vs [ ]

🐍 Output बताइए▶ Run
d = {"a": 1, "b": 2}
print(d.get("c"))
print(d.get("c", "not found"))
ANSWERNone
not found
← get() key न मिलने पर None (या दिया गया default) लौटाता है — error नहीं देता (d["c"] error देता)।

Q5. Set की Duplicate-Removal Power

🐍 Output बताइए▶ Run
s = {1, 2, 2, 3, 3, 3}
print(len(s))
ANSWER3
← Set duplicates रखता ही नहीं — {1, 2, 3} बना।

Q6. List Slicing से Copy

🐍 Output बताइए▶ Run
a = [1, 2, 3]
b = a[:]           # slice se copy
b.append(4)
print(a)
print(b)
ANSWER[1, 2, 3]
[1, 2, 3, 4]
← a[:] एक नई (अलग) list बनाती है — इसलिए b बदलने पर a सुरक्षित रहा!

Q7. Nested List Access

🐍 Output बताइए▶ Run
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(matrix[1][2])
print(matrix[2][0])
ANSWER6
7
← पहला index row चुनता है, दूसरा column — [1][2] यानी row 1 का index 2।

Q8. Dictionary Key Overwrite

🐍 Output बताइए▶ Run
d = {"a": 1, "b": 2, "a": 3}
print(d)
ANSWER{'a': 3, 'b': 2}
← Keys unique होनी चाहिए — दोहराई गई key की आखिरी value रहती है, पहली overwrite हो जाती है।

Q9. Set Operations Combo

🐍 Output बताइए▶ Run
A = {1, 2, 3}
B = {2, 3, 4}
print(A & B)
print(A - B)
print(A ^ B)
ANSWER{2, 3}
{1}
{1, 4}
← Intersection = common; Difference = A में है B में नहीं; Symmetric = दोनों में अलग-अलग जो है।

Q10. String Slicing Reverse Trick

🐍 Output बताइए▶ Run
s = "PROGRAMMING"
print(s[2:8:2])
ANSWEROGA
← index 2,4,6 (2 से 8 तक, step 2 में, 8 exclude) → O, G, A।

Q11. List में in operator

🐍 Output बताइए▶ Run
fruits = ["apple", "mango", "banana"]
print("mango" in fruits)
print("grape" not in fruits)
ANSWERTrue
True
← membership check — दोनों true क्योंकि mango मौजूद है और grape नहीं।

Q12. Tuple Immutability Error

🐍 क्या error आएगी?▶ Run
t = (1, 2, 3)
t[0] = 100
ANSWERTypeError: 'tuple' object does not support item assignment
← Tuple immutable है — किसी index पर direct assignment नहीं हो सकती।
5.8

💻 Practice Programs — List, Dict, Set का असली उपयोग

हर program इस chapter के data structures पर — real exam व practical दोनों के लिए ready!

Program 1 — Maximum, Minimum, Mean निकालना

🐍 stats.py▶ Run
marks = [67, 89, 45, 92, 78, 55]
print("Maximum:", max(marks))
print("Minimum:", min(marks))
print("Mean:", sum(marks) / len(marks))
OUTPUTMaximum: 92
Minimum: 45
Mean: 71.0

Program 2 — Linear Search (बिना built-in के)

🐍 linear_search.py▶ Run
nums = [23, 45, 12, 67, 34, 89]
target = int(input("Kya dhoondhna hai: "))
found = False
for i in range(len(nums)):
    if nums[i] == target:
        print(f"Mila! Index {i} par")
        found = True
        break
if not found:
    print("Nahi mila")
OUTPUT (input: 67)Mila! Index 3 par

Program 3 — Dictionary से Character Frequency Count

🐍 char_frequency.py▶ Run
text = "banana"
freq = {}
for ch in text:
    freq[ch] = freq.get(ch, 0) + 1
print(freq)
OUTPUT{'b': 1, 'a': 3, 'n': 2}

Program 4 — Student Marksheet (Dictionary)

🐍 marksheet.py▶ Run
marks = {"Hindi": 85, "Maths": 92, "Science": 78, "English": 88}
total = sum(marks.values())
percent = total / len(marks)
print(f"Total = {total}")
print(f"Percentage = {percent}%")
best = max(marks, key=marks.get)
print(f"Best subject: {best}")
OUTPUTTotal = 343
Percentage = 85.75%
Best subject: Maths

Program 5 — List से Duplicates हटाना (Set से)

🐍 remove_duplicates.py▶ Run
nums = [5, 2, 8, 2, 5, 9, 8, 1]
unique = list(set(nums))
print("Original:", nums)
print("Unique  :", unique)
OUTPUTOriginal: [5, 2, 8, 2, 5, 9, 8, 1]
Unique : [1, 2, 5, 8, 9]

Program 6 — Common Students दोनों Classes में (Set Intersection)

🐍 common_students.py▶ Run
science_club = {"Amit", "Priya", "Rahul", "Neha"}
sports_club = {"Priya", "Neha", "Karan"}
both = science_club & sports_club
print("Dono clubs me:", both)
OUTPUTDono clubs me: {'Priya', 'Neha'}

Program 7 — List Rotation (Slicing से)

🐍 list_rotation.py▶ Run
nums = [1, 2, 3, 4, 5]
k = 2   # kitna rotate karna hai
rotated = nums[k:] + nums[:k]
print("Original:", nums)
print("Rotated :", rotated)
OUTPUTOriginal: [1, 2, 3, 4, 5]
Rotated : [3, 4, 5, 1, 2]

Program 8 — Word Count Dictionary (sentence से)

🐍 word_count.py▶ Run
sentence = "python is easy python is powerful python rocks"
words = sentence.split()
count = {}
for w in words:
    count[w] = count.get(w, 0) + 1
print(count)
OUTPUT{'python': 3, 'is': 2, 'easy': 1, 'powerful': 1, 'rocks': 1}
Exam Point: Linear search, character/word frequency (dict.get() pattern), set से duplicates हटाना, Union/Intersection के real-world uses — ये सब O Level practical व theory दोनों में repeat होते हैं।
5.9

Summary — Quick Revision (Exam से पहले पढ़ें)

  • Sequence Types: String, List, Tuple, Range — ordered, index-based; Dict (3.7+ ordered), Set (unordered)।
  • Indexing: 0 से शुरू; negative index पीछे से (-1 = आखिरी)। Slicing: [start:stop:step], stop हमेशा excluded; [::-1] = reverse।
  • List [ ] — mutable, duplicates व mixed types allowed; append(), insert(), remove(), pop(), sort()।
  • Tuple ( ) — immutable, list से तेज़; (5,) tuple है पर (5) सिर्फ int; सिर्फ count() व index() methods।
  • Dictionary {key:value} — key से access (d["key"] या d.get("key")); keys unique व immutable; keys(), values(), items()।
  • Set { } — unique elements, unordered, indexing नहीं; set() खाली set, {} खाली dict; Union|, Intersection&, Difference−, Symmetric^।
  • Mutability: id() से जाँच — mutable (list/dict/set) में id() same रहती है modify पर; immutable (str/tuple/int) में नई id बनती है।
  • Aliasing warning: b = a से दोनों एक ही object refer करते हैं — copy चाहिए तो a[:] या list(a) उपयोग करें।
  • List Comprehension: [expression for item in sequence if condition] — compact तरीका नई list बनाने का।
5.10

Model Questions — 50 MCQs + 15 Theory Questions

❓ A. Multiple Choice Questions (50)

#प्रश्न
1

List किस symbol में लिखी जाती है?

(a) ( )(b) [ ](c) { }(d) < >
✔ सही उत्तर: (b) [ ]Square brackets।
2

Tuple किस symbol में लिखा जाता है?

(a) [ ](b) ( )(c) { }(d) # #
✔ सही उत्तर: (b) ( )Parentheses।
3

इनमें mutable कौन है?

(a) String(b) Tuple(c) List(d) int
✔ सही उत्तर: (c) ListList modify की जा सकती है।
4

इनमें immutable कौन है?

(a) List(b) Dict(c) Set(d) Tuple
✔ सही उत्तर: (d) Tupleबाकी तीनों mutable हैं।
5

Python में indexing शुरू होती है —

(a) 1 से(b) -1 से(c) 0 से(d) 10 से
✔ सही उत्तर: (c) 0 सेZero-based indexing।
6

lst[-1] देता है —

(a) पहला element(b) आखिरी element(c) Error(d) खाली list
✔ सही उत्तर: (b) आखिरी elementNegative index पीछे से गिनता है।
7

"PYTHON"[1:4] का output —

(a) PYT(b) YTH(c) THO(d) YTHO
✔ सही उत्तर: (b) YTHIndex 1,2,3 (4 exclude)।
8

Slicing में stop index —

(a) शामिल होता है(b) शामिल नहीं होता(c) हमेशा 0(d) हमेशा -1
✔ सही उत्तर: (b) शामिल नहीं होतायह Python का fundamental rule है।
9

text[::-1] करता है —

(a) Sort(b) Reverse(c) Copy(d) Delete
✔ सही उत्तर: (b) Reverseपूरी sequence उल्टी हो जाती है।
10

List में end पर element जोड़ने का method —

(a) add()(b) insert()(c) append()(d) push()
✔ सही उत्तर: (c) append()insert() specific position पर डालता है।
11

list.remove(x) हटाता है —

(a) index x को(b) value x को(c) पहला element(d) आखिरी element
✔ सही उत्तर: (b) value x कोvalue से पहला मिलान हटता है — pop() index से हटाता है।
12

[1,2,3] + [4,5] का output —

(a) [5,7](b) [1,2,3,4,5](c) Error(d) [1,2,3,[4,5]]
✔ सही उत्तर: (b) [1,2,3,4,5]+ list concatenation करता है।
13

List comprehension का सही syntax —

(a) [x for x in seq](b) (x for x in seq)(c) {x: x in seq}(d) x for x in seq
✔ सही उत्तर: (a) [x for x in seq]Square brackets में लिखा जाता है।
14

(5,) है —

(a) int(b) list(c) tuple(d) dict
✔ सही उत्तर: (c) tupleComma की वजह से — यह single-element tuple है।
15

(5) है —

(a) tuple(b) int(c) list(d) error
✔ सही उत्तर: (b) intComma नहीं है — bracket सिर्फ grouping है।
16

Tuple के मुख्य methods हैं —

(a) append, remove(b) count, index(c) add, discard(d) get, update
✔ सही उत्तर: (b) count, indexImmutable होने से modify करने वाले methods नहीं होते।
17

Tuple, List से तेज़ क्यों है?

(a) कम elements रखता है(b) Immutable होने से Python optimize करता है(c) सिर्फ numbers रखता है(d) कोई कारण नहीं
✔ सही उत्तर: (b) Immutable होने सेFixed memory allocation।
18

Dictionary किस symbol में लिखी जाती है?

(a) [ ](b) ( )(c) { }(d) < >
✔ सही उत्तर: (c) { }Curly braces, key:value pairs के साथ।
19

Dictionary की value access होती है —

(a) Index से(b) Key से(c) Position से(d) Random
✔ सही उत्तर: (b) Key सेd["key"] या d.get("key")।
20

d.get("x") अगर key न मिले तो देता है —

(a) Error(b) 0(c) None(d) खाली string
✔ सही उत्तर: (c) Noned["x"] error देता, get() safe है।
21

Dictionary keys होनी चाहिए —

(a) Mutable(b) Unique व Immutable(c) केवल numbers(d) Duplicate allowed
✔ सही उत्तर: (b) Unique व ImmutableList key नहीं बन सकती (mutable है)।
22

d = {"a":1,"b":2,"a":3} में d होगा —

(a) {"a":1,"b":2,"a":3}(b) {"a":3,"b":2}(c) Error(d) {"a":1,"b":2}
✔ सही उत्तर: (b) {"a":3,"b":2}Duplicate key की आखिरी value रहती है।
23

Dictionary के key-value pairs एक साथ देने वाला method —

(a) keys()(b) values()(c) items()(d) pairs()
✔ सही उत्तर: (c) items()for k,v in d.items() पैटर्न में उपयोग।
24

Set किस symbol में लिखा जाता है?

(a) [ ](b) ( )(c) { }(d) ⟨ ⟩
✔ सही उत्तर: (c) { }Dictionary जैसा ही symbol, पर सिर्फ values।
25

खाली set बनाने का सही तरीका —

(a) {}(b) set()(c) [](d) ()
✔ सही उत्तर: (b) set(){} खाली dictionary बनाता है, set नहीं!
26

{1,2,2,3,3} का length —

(a) 5(b) 3(c) 2(d) Error
✔ सही उत्तर: (b) 3Set duplicates automatically हटा देता है — {1,2,3}।
27

A | B (sets) करता है —

(a) Intersection(b) Union(c) Difference(d) XOR
✔ सही उत्तर: (b) Unionदोनों sets का सारा unique data।
28

A & B (sets) करता है —

(a) Union(b) Intersection(c) Difference(d) Copy
✔ सही उत्तर: (b) Intersectionदोनों में जो common है।
29

A - B (sets) करता है —

(a) Union(b) Intersection(c) Difference (A में है B में नहीं)(d) Symmetric
✔ सही उत्तर: (c) DifferenceA - B = A में है पर B में नहीं।
30

Set indexing support करता है क्या?

(a) हाँ(b) नहीं(c) कभी-कभी(d) सिर्फ negative
✔ सही उत्तर: (b) नहींSet unordered है, इसलिए s[0] जैसा कुछ नहीं चलता।
31

Mutable object modify करने पर id() —

(a) बदल जाती है(b) same रहती है(c) 0 हो जाती है(d) None हो जाती है
✔ सही उत्तर: (b) same रहती हैवही object अंदर से बदलता है — object create नहीं होता नया।
32

Immutable object modify करने पर id() —

(a) same रहती है(b) बदल जाती है(c) negative हो जाती है(d) कोई असर नहीं
✔ सही उत्तर: (b) बदल जाती हैनया object बनता है — पुराना वैसा ही रहता है।
33

b = a (list); b.append(1) करने पर a —

(a) नहीं बदलेगी(b) भी बदल जाएगी(c) Error आएगा(d) खाली हो जाएगी
✔ सही उत्तर: (b) भी बदल जाएगीb = a से दोनों एक ही object को refer करते हैं (aliasing)।
34

List की असली copy बनाने के लिए —

(a) b = a(b) b = a[:](c) b = a + 1(d) b == a
✔ सही उत्तर: (b) b = a[:]Slicing से नया object बनता है — copy() भी चलता है।
35

t = (1, [2,3], 4); t[1].append(9) करने पर —

(a) Error आएगा(b) List के अंदर 9 जुड़ जाएगा(c) कुछ नहीं होगा(d) पूरा tuple बदल जाएगा
✔ सही उत्तर: (b) List के अंदर 9 जुड़ जाएगाTuple के अंदर की mutable list खुद बदल सकती है।
36

List method जो elements को ascending order में रखता है —

(a) order()(b) sort()(c) arrange()(d) rank()
✔ सही उत्तर: (b) sort()in-place sort करता है।
37

max([12, 45, 3, 67, 21]) का output —

(a) 3(b) 67(c) 21(d) 12
✔ सही उत्तर: (b) 67Largest value।
38

len({"a":1, "b":2, "c":3}) का output —

(a) 6(b) 3(c) 1(d) Error
✔ सही उत्तर: (b) 3Dictionary में keys की गिनती।
39

[1,2,3] * 2 का output —

(a) [2,4,6](b) [1,2,3,1,2,3](c) [1,2,3,2](d) Error
✔ सही उत्तर: (b) [1,2,3,1,2,3]* list की repetition करता है, multiplication नहीं।
40

Nested list matrix[1][2] का मतलब —

(a) row 2, col 1(b) row 1, col 2(c) index 12(d) Error
✔ सही उत्तर: (b) row 1, col 2पहला index row चुनता है, दूसरा column।
41

tuple to list convert करने के लिए —

(a) tuple(x)(b) list(x)(c) set(x)(d) dict(x)
✔ सही उत्तर: (b) list(x)Type-casting function।
42

List से duplicates हटाने का सबसे तेज़ तरीका —

(a) for loop से(b) list(set(x))(c) sort()(d) reverse()
✔ सही उत्तर: (b) list(set(x))Set में duplicates ही नहीं रहते।
43

Dictionary से key हटाने का method —

(a) remove()(b) delete()(c) pop()(d) discard()
✔ सही उत्तर: (c) pop()d.pop("key") — set का discard() अलग है।
44

Set से element हटाने पर जो error नहीं देता —

(a) remove()(b) discard()(c) pop()(d) delete()
✔ सही उत्तर: (b) discard()remove() न मिलने पर KeyError देता है।
45

Tuple unpacking का उदाहरण —

(a) x = (1,2,3)(b) a,b,c = (1,2,3)(c) x[0] = 1(d) x.append(1)
✔ सही उत्तर: (b) a,b,c = (1,2,3)एक साथ कई variables में values assign होती हैं।
46

"apple" in ["apple","mango"] का output —

(a) True(b) False(c) 0(d) Error
✔ सही उत्तर: (a) TrueMembership test — apple list में मौजूद है।
47

List comprehension [n*n for n in [1,2,3]] का output —

(a) [1,2,3](b) [1,4,9](c) [2,4,6](d) Error
✔ सही उत्तर: (b) [1,4,9]हर n का square।
48

Dictionary Python 3.7+ में —

(a) पूरी तरह unordered(b) insertion order maintain करती है(c) sorted रहती है(d) random order
✔ सही उत्तर: (b) insertion order maintain करती है3.7 से पहले guarantee नहीं थी।
49

list.pop() बिना index के हटाता है —

(a) पहला element(b) आखिरी element(c) random element(d) सभी elements
✔ सही उत्तर: (b) आखिरी elementDefault index -1 होता है।
50

Sequence Data Types में शामिल नहीं है —

(a) String(b) List(c) Tuple(d) Set
✔ सही उत्तर: (d) SetSet unordered है, इसलिए सही मायने में sequence नहीं।

📝 B. 15 Theory Questions (Short Answers)

  1. Sequence Data Types क्या हैं? उदाहरण दीजिए।Items का ordered collection जहाँ हर item का index होता है — String, List, Tuple, Range इसके उदाहरण हैं।
  2. Indexing और Slicing में अंतर बताइए।Indexing sequence[i] से एक element access करती है; Slicing sequence[start:stop:step] से एक range/subsequence निकालती है — stop हमेशा exclude होता है।
  3. List और Tuple में 4 अंतर लिखिए।List [ ] mutable, धीमी, ज़्यादा memory, कई methods; Tuple ( ) immutable, तेज़, कम memory, सिर्फ count()/index() methods।
  4. (5,) और (5) में क्या फर्क है?(5,) comma के कारण single-element tuple है; (5) सिर्फ integer 5 है — bracket को math grouping की तरह लिया जाता है, tuple नहीं बनता।
  5. Dictionary की keys के क्या नियम हैं?Keys unique होनी चाहिए (repeat हुई तो आखिरी value रहती है) और immutable होनी चाहिए (string, number, tuple चल सकती है; list नहीं क्योंकि वह mutable है)।
  6. Dictionary में d["key"] और d.get("key") में अंतर बताइए।d["key"] key न मिलने पर KeyError देता है; d.get("key") None (या दिया गया default) return करता है — यह safe access है।
  7. Set क्या है? इसकी 3 विशेषताएँ लिखिए।{ } में unique, unordered, mutable collection। विशेषताएँ — duplicates नहीं होतीं, indexing/slicing नहीं होती, mathematical operations (Union, Intersection आदि) के लिए बना है।
  8. Union, Intersection, Difference व Symmetric Difference के symbols व मतलब लिखिए।| Union (दोनों का सारा data), & Intersection (सिर्फ common), − Difference (A में है B में नहीं), ^ Symmetric Difference (दोनों में जो अलग-अलग है)।
  9. Mutability क्या है? id() से कैसे जाँचते हैं?Object की content बदलने की क्षमता। id() function से पहले व बाद की memory address compare करते हैं — same रहे तो mutable (list/dict/set), बदल जाए तो immutable (str/tuple/int)।
  10. Aliasing (b = a) की समस्या समझाइए।b = a करने पर दोनों variables एक ही object को refer करते हैं — इसलिए b को modify करने पर a भी बदल जाता है (mutable objects में)। असली copy के लिए a[:] या a.copy() उपयोग करें।
  11. List Comprehension क्या है? Syntax लिखिए।एक compact तरीका नई list बनाने का — [expression for item in sequence if condition]। जैसे [n*n for n in range(5)] squares की list बनाता है।
  12. Nested List क्या है? उदाहरण दीजिए।List के अंदर list — जैसे matrix = [[1,2],[3,4]]। matrix[0][1] से पहली row का दूसरा element (2) मिलता है — 2D data (जैसे matrices) के लिए उपयोगी।
  13. Tuple Unpacking क्या है?Tuple की values को एक साथ कई variables में assign करना — student = ("Amit", 20); name, age = student। Elements की संख्या variables की संख्या से मेल खानी चाहिए।
  14. List से duplicates हटाने के 2 तरीके बताइए।1) Set का उपयोग: list(set(original_list)) — सबसे तेज़ पर order बदल सकता है। 2) Loop से: नई खाली list बनाकर हर item को "if not in" check करके add करना — order बना रहता है।
  15. Dictionary से character/word frequency कैसे count करते हैं?freq = {} बनाकर हर item पर freq[item] = freq.get(item, 0) + 1 चलाते हैं — get() से अगर key पहले से न हो तो 0 मिलता है, फिर 1 जुड़ जाता है। हर बार मिलने पर count बढ़ता जाता है।
Revision Tip: (5,) vs (5), d.get() vs d["key"], set() vs {}, aliasing (b=a) व id() — ये 4 concepts हर exam में किसी न किसी रूप में trap के रूप में आते हैं। Section 5.7 के output questions ज़रूर दोबारा करें!
FAQ

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

List और Tuple में मुख्य अंतर क्या है?
List [ ] में लिखी जाती है और mutable है (elements बदल सकते हैं); Tuple ( ) में लिखा जाता है और immutable है (एक बार बनने के बाद बदला नहीं जा सकता)। Tuple lists से तेज़ व कम memory लेता है।
Slicing कैसे काम करती है?
sequence[start:stop:step] से किसी sequence का हिस्सा निकालते हैं — start से शुरू, stop से पहले तक (stop शामिल नहीं), step जितनी दूरी पर। जैसे text[1:4] में index 1,2,3 मिलते हैं। text[::-1] पूरी string को उल्टा कर देता है।
Dictionary क्या है और List से कैसे अलग है?
Dictionary key-value pairs { } में store करती है और keys से access होती है (student['name']); List index-based [0,1,2...] से access होती है। Dictionary की keys unique व immutable होनी चाहिए।
Mutable और Immutable में क्या अंतर है, उदाहरण सहित?
Mutable objects (list, dict, set) को modify करने पर id() same रहती है — वही object बदलता है। Immutable objects (str, tuple, int) को बदलने की कोशिश पर नया object बनता है, id() बदल जाती है। यह id() फंक्शन से जाँचा जाता है।
Set क्या है और इसका उपयोग कब करें?
Set { } में unique elements की unordered collection है — duplicates automatically हट जाते हैं। Union (|), Intersection (&), Difference (-) जैसे mathematical operations और list से duplicates हटाने के लिए उपयोगी।

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

Chapter 6 में Functions — def, parameters, return values, default arguments व scope की पूरी दुनिया।

Chapter 6 पढ़ें ➜