Python List In Hindi | Python Programming in Hindi

Python List In Hindi In Python Programming

Python Programming ek bahut hi popular aur powerful language hai, jo aaj ke samay mein bahut use hoti hai. Python ko use karke hum bahut saari cheezein kar sakte hain jaise ki web development, data analysis, artificial intelligence, aur bhi bahut kuch. Iss article mein hum specifically "Python List In Hindi" ke bare mein jaanenge aur Python ke lists ko kaise use karna hai yeh seekhenge.


Python List In Hindi | Python Programming in Hindi
Python List In Hindi | Python Programming in Hindi

Python List In Hindi: Python list, Python ke built-in data types mein se ek hai, jo data collections ko store karne ke kaam aati hai. List mein hum multiple values ko ek hi variable mein store kar sakte hain. Isse pehle jo variables hum initialize karte the, woh sirf single value store kar sakte the, lekin list is problem ko solve karti hai.

यह भी पढ़ें: 250+ Free Python Projects with Source Code: From Beginner to Advanced

Python List: Introduction

List ek ordered aur changeable collection hai jo duplicate items ko bhi allow karta hai. Lists ko hum square brackets [ ] ka use karke create kar sakte hain. Yeh kuch properties hain jo lists ko baaki data types se alag banati hain:

Ordered: List ke items order mein store hote hain. Matlab, jis order mein aap items ko list mein insert karte ho, ussi order mein woh store hote hain.

Duplicate Items: List mein duplicate items allow hain. Matlab, ek hi item ko aap multiple baar list mein insert kar sakte ho.

Changeable
: List ke items changeable hote hain. Matlab, aap list mein items ko add, remove ya update kar sakte ho.

Example: List Creation and Basic Operations

Chaliye ek simple example dekhte hain list create karne ka aur uske basic operations ka:

# List creation using square brackets
list_var = [12, 45, 56, 5, 76, 78, 78, 45, 12]
print(list_var)
# Output: [12, 45, 56, 5, 76, 78, 78, 45, 12]

Note: List mein same type ke items hone zaroori nahi hai. Aap kisi bhi type ke elements insert kar sakte hain jaise String, Boolean, Numeric etc.

# Example with mixed data types
list_var = ["name", 34, 56.78, True]
print(list_var)
# Output: ['name', 34, 56.78, True]

Python List Iteration

List ke items indexed hote hain, matlab har item ka ek unique index hota hai jo 0 se start hota hai. Index hone ki wajah se hum list ke items ko easily access kar sakte hain aur iterate kar sakte hain using loops.

Example: Iterate Through a List

list_var = [12, 45, 56, 5, 76, 78, 78, 45, 12]
for item in list_var:
     print(item)

Output:

12 45 56 5 76 78 78 45 12

List Length & Type

List ki length jaanne ke liye hum len() function ka use karte hain aur type jaanne ke liye type() function ka.

Example: Length and Type of List

list_var = [12, 45, 56, 5, 76, 78, 78, 45, 12]
print('list length:', len(list_var)) 
# Output: list length: 9
print('type:', type(list_var))
# Output: type: <class 'list'>

Access Single Item from List

Index number ka use karke hum kisi bhi item ko directly access kar sakte hain.

Example: Access Items Using Index

# Accessing 2nd item
print(list_var[1]) # Output: 45
# Accessing 5th item
print(list_var[4]) # Output: 76

Colon : ka use karke hum list ke ek particular part ko bhi access kar sakte hain.

Example: Slicing the List

list_var = [12, 45, 56, 5, 76, 78, 78, 45, 12]
print(list_var[2:]) # Output: [56, 5, 76, 78, 78, 45, 12] (3rd index se aage sab items)
print(list_var[4:6]) # Output: [76, 78] (4th se 6th index tak ke items, 6th item ko chhod kar)
print(list_var[:5]) # Output: [12, 45, 56, 5, 76] (Starting se 5th index tak ke items)
print(list_var[-1]) # Output: 12 (Last item)
print(list_var[3:-1]) # Output: [5, 76, 78, 78, 45] (3rd index se n-1 th index tak ke items)
print(list_var[-8:-1]) # Output: [45, 56, 5, 76, 78, 78, 45] (8th index from last se -1 index tak)

Python List Methods

Python list ke saath kuch built-in methods bhi aati hain jo list ke items ko manipulate karne mein help karti hain. Yeh methods humare tasks ko asaan bana deti hain.

Commonly Used List Methods

append(): List ke end mein ek item add karta hai.
insert(): List ke kisi specific position par item insert karta hai.
remove(): List se specified item ko remove karta hai.
pop(): List se specified position ka item remove karta hai (agar position specify nahi kiya to last item remove hota hai).
clear(): List ke saare items remove kar deta hai.
index(): List ke specified item ka index return karta hai.
count(): List mein specified item ke occurrences count karta hai.
sort(): List ke items ko ascending order mein sort karta hai.
reverse(): List ke items ko reverse order mein kar deta hai.
copy()
: List ka ek copy banata hai.

Example: Using List Methods

list_var = [12, 45, 56, 5, 76] # Append list_var.append(90)
print(list_var) # Output: [12, 45, 56, 5, 76, 90] # Insert list_var.insert(2, 100)
print(list_var) # Output: [12, 45, 100, 56, 5, 76, 90] # Remove list_var.remove(5)
print(list_var) # Output: [12, 45, 100, 56, 76, 90] # Pop list_var.pop()
print(list_var) # Output: [12, 45, 100, 56, 76] # Clear list_var.clear()
print(list_var) # Output: [] # Index list_var = [12, 45, 56, 5, 76]
print(list_var.index(56)) # Output: 2 # Count
print(list_var.count(45)) # Output: 1 # Sort list_var.sort()
print(list_var) # Output: [5, 12, 45, 56, 76] # Reverse list_var.reverse()
print(list_var) # Output: [76, 56, 45, 12, 5] # Copy list_copy = list_var.copy()
print(list_copy) # Output: [76, 56, 45, 12, 5]

List Comprehensions

List comprehension ek concise way hai ek new list create karne ka, especially jab hume ek existing list ko kisi rule ke according modify karke new list banani hoti hai.

Example: List Comprehension

# Square of each item
list_var = [1, 2, 3, 4, 5]
squares = [x**2 for x in list_var]
print(squares)
# Output: [1, 4, 9, 16, 25]

# Even numbers
even_numbers = [x for x in list_var if x % 2 == 0]
print(even_numbers)
# Output: [2, 4]

Nested Lists

Nested list ek aisi list hoti hai jisme doosri list bhi elements ke roop mein hoti hain. Yeh tab useful hoti hain jab hume matrix ya table-like structure ko represent karna hota hai.

Example: Nested Lists

nested_list = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
print(nested_list[0][1]) # Output: 2
print(nested_list[2][2]) # Output: 9

List vs. Other Data Types

List vs. Tuple

  • List: Changeable, allows duplicate items, mutable.

  • Tuple: Unchangeable (immutable), allows duplicate items, fixed size.

Example: List and Tuple

list_var = [1, 2, 3]
tuple_var = (1, 2, 3)
list_var[0] = 10
print(list_var)

# Output: [10, 2, 3]
# tuple_var[0] = 10
# Error: 'tuple' object does not support item assignment

List vs. Set

  • List: Ordered, allows duplicate items, mutable.

  • Set: Unordered, does not allow duplicate items, mutable but does not support indexing.

Example: List and Set

list_var = [1, 2, 2, 3] 
set_var = {1, 2, 2, 3} 
print(list_var) 
# Output: [1, 2, 2, 3] 
print(set_var) 
# Output: {1, 2, 3}

List vs. Dictionary

  • List: Ordered, allows duplicate items, mutable.

  • Dictionary: Key-value pairs, keys are unique, mutable but keys must be immutable.

Example: List and Dictionary

list_var = ["apple", "banana", "cherry"]
dict_var = {"name": "John", "age": 30, "city": "New York"}
print(list_var[0])
# Output: apple
print(dict_var["name"])
# Output: John

Conclusion: Python List In Hindi

Python list ek bahut hi powerful aur flexible data structure hai jo humare kaam ko bahut asaan bana deti hai. Is article mein humne dekha ki kaise list create karte hain, kaise uske items ko access karte hain, kaise list ke methods ka use karte hain aur kaise list comprehensions aur nested lists ko use karte hain.

Yeh comprehensive guide Python Programming in Hindi ke liye hai jo beginners aur advanced users dono ke liye useful ho sakta hai. Agar aapko yeh article "Python List In Hindi" pasand aaya ho, toh apne doston ke saath zaroor share karein aur Python ke aur bhi topics ke liye humare articles padhe.

यह भी पढ़ें: Python Programming In Hindi | Python Tutorials In Hindi

और नया पुराने

संपर्क फ़ॉर्म