Programming में अक्सर हमें एक ही प्रकार के कई Data को एक साथ Store करने की आवश्यकता होती है। उदाहरण के लिए किसी कक्षा के सभी विद्यार्थियों के नाम, किसी दुकान के सभी उत्पादों की सूची, किसी परीक्षा के अंक या किसी कंपनी के कर्मचारियों की जानकारी। यदि प्रत्येक Value के लिए अलग-अलग Variable बनाए जाएँ, तो Program लंबा, जटिल और कठिन हो जाएगा।
इसी समस्या का समाधान List है।
List Python का सबसे अधिक उपयोग होने वाला Collection Data Type है। इसमें एक साथ कई Values Store की जा सकती हैं। ये Values समान (Homogeneous) या अलग-अलग प्रकार (Heterogeneous) की हो सकती हैं। List में Data का क्रम (Order) बना रहता है, Indexing उपलब्ध होती है तथा आवश्यकता अनुसार इसमें नए Elements जोड़ना, हटाना या बदलना संभव है।
Python में List Mutable होती है, अर्थात् List बनने के बाद भी उसके Elements को बदला जा सकता है।
List Python का एक Built-in Collection Data Type है, जिसमें एक या अधिक Values को Square Brackets [ ] के अंदर Comma (,) द्वारा अलग करके लिखा जाता है।
List में किसी भी प्रकार का Data Store किया जा सकता है, जैसे Integer, Float, String, Boolean, यहाँ तक कि दूसरी List भी।
list_name = [item1, item2, item3]
students = ["Rahul", "Amit", "Neha", "Priya"]
marks = [85, 92, 78, 88]
mixed = ["Python", 100, 99.5, True]
List की विशेषताएँ (Characteristics of List)
- List एक Ordered Collection है।
- List Mutable होती है।
- इसमें Duplicate Values Store की जा सकती हैं।
- इसमें Different Data Types Store किए जा सकते हैं।
- List में Positive तथा Negative दोनों प्रकार की Indexing होती है।
- List Dynamic होती है, अर्थात इसका Size बढ़ाया या घटाया जा सकता है।
- List में Nested List भी बनाई जा सकती है।
fruits = ["Apple", "Mango", "Banana"]
data = []
numbers = list((10, 20, 30, 40))
letters = list("Python")
Output
['P', 'y', 't', 'h', 'o', 'n']
data = [
"Rahul",
22,
78.5,
True,
["Math", "Science"]
]
यह Python की सबसे बड़ी विशेषताओं में से एक है कि List में विभिन्न प्रकार के Data को एक साथ रखा जा सकता है।
किसी List में कुल Elements की संख्या जानने के लिए len() Function का उपयोग किया जाता है।
fruits = ["Apple", "Mango", "Banana"]
print(len(fruits))
Output
3
List के प्रत्येक Element का एक Index होता है।
Element : Apple Mango Banana Orange
Index : 0 1 2 3
Negative Index
Element : Apple Mango Banana Orange
Index : -4 -3 -2 -1
fruits = ["Apple", "Mango", "Banana"]
print(fruits[0])
print(fruits[2])
Output
Apple
Banana
print(fruits[-1])
Output
Banana
List का कोई भाग प्राप्त करने के लिए Slicing का उपयोग किया जाता है।
list[start:stop:step]
numbers = [10,20,30,40,50,60]
print(numbers[1:4])
Output
[20, 30, 40]
print(numbers[:3])
Output
[10,20,30]
print(numbers[3:])
Output
[40,50,60]
print(numbers[::-1])
Output
[60,50,40,30,20,10]
String की तरह List Immutable नहीं होती।
इसलिए List बनने के बाद उसके Elements को बदला जा सकता है।
fruits = ["Apple","Mango","Banana"]
fruits[1] = "Orange"
print(fruits)
Output
['Apple', 'Orange', 'Banana']
List के प्रत्येक Element पर कार्य करने के लिए Loop का उपयोग किया जाता है।
fruits = ["Apple","Mango","Banana"]
for fruit in fruits:
print(fruit)
fruits=["Apple","Mango","Banana"]
print("Apple" in fruits)
print("Orange" not in fruits)
Output
True
True
a=[1,2]
b=[3,4]
print(a+b)
Output
[1,2,3,4]
print([1,2]*3)
Output
[1,2,1,2,1,2]
List के अंदर दूसरी List को Nested List कहा जाता है।
students = [
["Rahul",85],
["Amit",90],
["Neha",88]
]
Nested List में Indexing
print(students[0][0])
Output
Rahul
Python List पर निम्न Built-in Functions उपयोग किए जाते हैं—
|
Function |
कार्य |
|
len() |
कुल Elements |
|
max() |
सबसे बड़ा Element |
|
min() |
सबसे छोटा Element |
|
sum() |
कुल योग |
|
sorted() |
Sorting |
|
reversed() |
Reverse Iterator |
|
any() |
कोई एक True |
|
all() |
सभी True |
numbers=[10,20,30,40]
print(len(numbers))
print(sum(numbers))
print(max(numbers))
print(min(numbers))
Python List के लगभग सभी महत्वपूर्ण Methods:
- append()
- extend()
- insert()
- remove()
- pop()
- clear()
- copy()
- index()
- count()
- sort()
- reverse()
इन सभी Methods का विस्तृत अध्ययन अगले Master Guide "Python List Methods in Hindi" में किया जाएगा, जहाँ प्रत्येक Method का Syntax, Examples, Programs और Interview Questions दिए जाएँगे।
Program 1 – List के सभी Elements Print करें
numbers=[10,20,30,40,50]
for i in numbers:
print(i)
numbers=[10,20,30,40]
print(sum(numbers))
numbers=[25,12,90,45]
print(max(numbers))
numbers=[25,12,90,45]
print(min(numbers))
numbers=[10,20,30,40]
print(numbers[::-1])
numbers=[10,20,30,40]
if 20 in numbers:
print("Found")
else:
print("Not Found")
numbers=[10,20]
print(numbers[5])
❌ Error क्योंकि Index उपलब्ध नहीं है।
numbers=[10,20]
print(numbers+"Python")
❌ List और String को + से नहीं जोड़ सकते।
- Related Data को हमेशा List में Store करें।
- Index Access करते समय उसकी सीमा (Range) जाँचें।
- जहाँ संभव हो for Loop का उपयोग करें।
- अनावश्यक Nested Lists से बचें।
- बड़ी Lists पर Built-in Functions का उपयोग करें।
परीक्षा की दृष्टि से महत्वपूर्ण तथ्य
- List एक Mutable Ordered Collection है।
- List Square Brackets [ ] में लिखी जाती है।
- Duplicate Values Allowed होती हैं।
- Different Data Types Store किए जा सकते हैं।
- Positive एवं Negative दोनों प्रकार की Indexing उपलब्ध होती है।
- len(), sum(), max(), min() List पर सबसे अधिक उपयोग होने वाले Functions हैं।
Frequently Asked Questions (FAQs)
प्रश्न 1. Python List क्या है?
List Python का Mutable Collection Data Type है जिसमें कई Values Store की जा सकती हैं।
प्रश्न 2. List Mutable क्यों कहलाती है?
क्योंकि List बनने के बाद उसके Elements को बदला, जोड़ा या हटाया जा सकता है।
प्रश्न 3. List में Duplicate Values रख सकते हैं?
हाँ, रख सकते हैं।
प्रश्न 4. List में अलग-अलग Data Types रख सकते हैं?
हाँ, Integer, Float, String, Boolean और दूसरी List भी रख सकते हैं।
प्रश्न 5. List और Tuple में मुख्य अंतर क्या है?
List Mutable होती है जबकि Tuple Immutable होती है।
- List = Ordered Collection
- Mutable = हाँ
- Duplicate = Allowed
- Mixed Data Types = Allowed
- Indexing = Positive + Negative
- Slicing = Supported
- Nested List = Supported
- len(), sum(), max(), min() = महत्वपूर्ण Functions
Python List Methods (append(), extend(), insert(), remove(), pop(), clear(), index(), count(), sort(), reverse(), copy()) – Complete Guide in Hindi
यह Chapter भी String Methods की तरह एक Master Guide होगा, जिसमें सभी List Methods को एक ही Article में विस्तार से समझाया जाएगा।