मुख्य कंटेंट पर जाएं
Python List in Hindi – List, Indexing, Slicing, List Methods और Practical Programs
PYTHON PROGRAMMING 12 मिनट पढ़ें 1 बार पढ़ा गया

Python List in Hindi – List, Indexing, Slicing, List Methods और Practical Programs

Lavkush Chakrawarti

परिचय

List क्या है?

List का Syntax

उदाहरण

List की विशेषताएँ (Characteristics of List)

List बनाने के तरीके

1. Direct List

2. Empty List

3. list() Constructor

4. String से List

List में विभिन्न Data Types

List की Length

List Indexing

Positive Indexing

Negative Indexing

List Slicing

Syntax

उदाहरण

List Mutable क्यों होती है?

List Traversing

Membership Operators

List Concatenation

List Repetition

Nested List

Built-in Functions

उदाहरण

List Methods (Complete List)

Practical Programs

Program 1 – List के सभी Elements Print करें

Program 2 – List का Sum

Program 3 – Largest Number

Program 4 – Smallest Number

Program 5 – Reverse List

Program 6 – Element Search

Common Errors

IndexError

TypeError

Best Practices

परीक्षा की दृष्टि से महत्वपूर्ण तथ्य

Frequently Asked Questions (FAQs)

Quick Revision

अगला अध्याय

 

परिचय

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 क्या है?

List Python का एक Built-in Collection Data Type है, जिसमें एक या अधिक Values को Square Brackets [ ] के अंदर Comma (,) द्वारा अलग करके लिखा जाता है।

List में किसी भी प्रकार का Data Store किया जा सकता है, जैसे Integer, Float, String, Boolean, यहाँ तक कि दूसरी List भी।

 

List का Syntax

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 भी बनाई जा सकती है।

 

List बनाने के तरीके

  1. Direct List

fruits = ["Apple", "Mango", "Banana"]

 

  1. Empty List

data = []

 

  1. list() Constructor

numbers = list((10, 20, 30, 40))

 

  1. String से List

letters = list("Python")

Output

['P', 'y', 't', 'h', 'o', 'n']

 

List में विभिन्न Data Types

data = [

    "Rahul",

    22,

    78.5,

    True,

    ["Math", "Science"]

]

यह Python की सबसे बड़ी विशेषताओं में से एक है कि List में विभिन्न प्रकार के Data को एक साथ रखा जा सकता है।

 

List की Length

किसी List में कुल Elements की संख्या जानने के लिए len() Function का उपयोग किया जाता है।

fruits = ["Apple", "Mango", "Banana"]

 

print(len(fruits))

Output

3

 

List Indexing

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

 

Positive Indexing

fruits = ["Apple", "Mango", "Banana"]

 

print(fruits[0])

print(fruits[2])

Output

Apple

Banana

 

Negative Indexing

print(fruits[-1])

Output

Banana

 

List Slicing

List का कोई भाग प्राप्त करने के लिए Slicing का उपयोग किया जाता है।

Syntax

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]

 

List Mutable क्यों होती है?

String की तरह List Immutable नहीं होती।

इसलिए List बनने के बाद उसके Elements को बदला जा सकता है।

fruits = ["Apple","Mango","Banana"]

 

fruits[1] = "Orange"

 

print(fruits)

Output

['Apple', 'Orange', 'Banana']

 

List Traversing

List के प्रत्येक Element पर कार्य करने के लिए Loop का उपयोग किया जाता है।

fruits = ["Apple","Mango","Banana"]

 

for fruit in fruits:

    print(fruit)

 

Membership Operators

fruits=["Apple","Mango","Banana"]

 

print("Apple" in fruits)

print("Orange" not in fruits)

Output

True

True

 

List Concatenation

a=[1,2]

b=[3,4]

 

print(a+b)

Output

[1,2,3,4]

 

List Repetition

print([1,2]*3)

Output

[1,2,1,2,1,2]

 

Nested List

List के अंदर दूसरी List को Nested List कहा जाता है।

students = [

    ["Rahul",85],

    ["Amit",90],

    ["Neha",88]

]

Nested List में Indexing

print(students[0][0])

Output

Rahul

 

Built-in Functions

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

 

List Methods (Complete List)

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 दिए जाएँगे।

 

Practical Programs

Program 1 – List के सभी Elements Print करें

numbers=[10,20,30,40,50]

 

for i in numbers:

    print(i)

 

Program 2 – List का Sum

numbers=[10,20,30,40]

 

print(sum(numbers))

 

Program 3 – Largest Number

numbers=[25,12,90,45]

 

print(max(numbers))

 

Program 4 – Smallest Number

numbers=[25,12,90,45]

 

print(min(numbers))

 

Program 5 – Reverse List

numbers=[10,20,30,40]

 

print(numbers[::-1])

 

Program 6 – Element Search

numbers=[10,20,30,40]

 

if 20 in numbers:

    print("Found")

else:

    print("Not Found")

 

Common Errors

IndexError

numbers=[10,20]

 

print(numbers[5])

❌ Error क्योंकि Index उपलब्ध नहीं है।

 

TypeError

numbers=[10,20]

 

print(numbers+"Python")

❌ List और String को + से नहीं जोड़ सकते।

 

Best Practices

  • 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 होती है।

 

Quick Revision

  • 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 में विस्तार से समझाया जाएगा।

 

निष्कर्ष (Conclusion)

Python List की पूरी जानकारी हिंदी में। List क्या है, List Creation, Indexing, Slicing, Nested List, List Methods, List Comprehension, Built-in Functions, 50+ Examples और Practical Programs सीखें।