Data Handling & Collections in Python (Hindi)

Data Handling & Collections in Python (Hindi)

🧩 WEEK 2 — Data Handling & Collections in Python

Goal: इस हफ्ते हम Python के चार सबसे उपयोगी डेटा स्ट्रक्चर्स सीखेंगे: Lists, Tuples, Sets, और Dictionaries। हर दिन के लिए examples, mini projects, और practice tasks होंगे ताकि आप अच्छे से समझ सकें।

Day 8: Lists — Your Python Superpower for Data Storage

Explanation: Lists Python का सबसे flexible डेटा स्ट्रक्चर है। इसमें आप numbers, strings, और even other lists store कर सकते हैं। Lists ordered और mutable होती हैं।

Python में lists ऐसे containers होते हैं, जो हमें multiple items एक साथ store करने की सुविधा देते हैं। Lists बहुत flexible होती हैं — आप इसमें numbers, strings, या और lists भी रख सकते हैं। Lists का सबसे बड़ा advantage यह है कि आप इसमें items को dynamically add, remove, या modify कर सकते हैं।

Real-Life Analogy

सोचिए आप अपने daily tasks manage कर रहे हैं। आप सुबह “Buy groceries” लिखते हैं, फिर बाद में “Complete Python project” add करते हैं। Lists बिल्कुल वैसे ही काम करती हैं। आप उन्हें console में ही नहीं, बल्कि GUI में भी manage कर सकते हैं।

Examples:

# List बनाना
fruits = ["Apple", "Banana", "Mango"]

# Access elements
print(fruits[0])  # Apple

# Add elements
fruits.append("Orange")

# Remove elements
fruits.remove("Banana")

# Loop through list
for fruit in fruits:
    print(fruit)

Output:
Apple
Apple
Mango
Orange

🎯 Mini Project: To-Do List Manager
- User से tasks input लें
- List में store करें
- Task complete होने पर remove करें
- पूरा list दिखाएं
Tasks for practice:
  • अपनी 5 पसंदीदा movies की list बनाइए।
  • List में एक और movie जोड़िए।
  • किसी एक movie को remove कीजिए।
  • List को alphabetically sort कीजिए।
  • Loop से हर movie print कीजिए।

Day 9: Tuples and Sets — Organize Data Like a Pro

Tuples: Immutable और Ordered।

student = ("Rahul", 19, "Science")
print(student[0])  # Rahul

Sets: Unique items only और Unordered।

roll_numbers = {101, 102, 103, 101}  # Duplicate removed automatically
print(roll_numbers)
  • Tuples: Immutable lists हैं। एक बार created होने के बाद आप उन्हें change नहीं कर सकते।
  • Sets: Unique collections हैं। यह automatically duplicates remove कर देते हैं।

Real-Life Analogy

Tuples → GPS coordinates की तरह हैं जो fixed होते हैं।
Sets → Guest list की तरह हैं जिसमें किसी का duplicate entry नहीं हो सकता।

🎯 Mini Task: एक set बनाइए जिसमें student roll numbers हों (duplicates auto remove)।
Tasks for practice:
  • 5 fruit names के tuple बनाइए।
  • Tuple का length print कीजिए।
  • एक set बनाइए जिसमें 10 random numbers हों।
  • Set में duplicate number add कीजिए और देखिए क्या होता है।
  • दो sets का union और intersection calculate कीजिए।

Day 10: Dictionaries — The Real-World Data Structure

Explanation: Key-Value pair में data store करने के लिए। Unordered लेकिन keys unique होती हैं।

जब lists और sets हमें collections manage करने में मदद करते हैं, तो dictionaries एक step आगे जाती हैं। Python की dictionaries key-value pairs में data store करती हैं। इसका मतलब है कि हर item के पास एक unique key होती है जिससे आप उसे आसानी से access कर सकते हैं।

Real-Life Analogy

सोचिए आपके पास एक address book है। हर person का नाम (key) और उसका phone number (value) है। जब आपको किसी व्यक्ति का number चाहिए, आप उसका नाम देख कर तुरंत access कर सकते हैं। Dictionaries बिल्कुल ऐसा ही करती हैं।

contact = {
    "Name": "Skill and Dedication",
    "Phone": "9876543210",
    "Email": "abc@gmail.com"
}

# Access value
print(contact["Name"])

# Add new entry
contact["Address"] = "Delhi"

# Loop through dictionary
for key, value in contact.items():
    print(key, ":", value)
🎯 Mini Project: Contact Book App
- Contact add, delete, update करें।
- Search by name।
Tasks for practice:
  • एक dictionary बनाइए जिसमें 3 students का marks store हो।
  • एक student का marks update कीजिए।
  • सभी students के names print कीजिए।
  • Dictionary में नया student add कीजिए।
  • Dictionary से एक student delete कीजिए।

Day 11: Looping Through Data — for & while with Lists

Explanation: Lists, Tuples, Sets, Dictionaries में loop करके data process कर सकते हैं।

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

# for loop
for fruit in fruits:
    print(fruit)

# while loop
i = 0
while i < len(fruits):
    print(fruits[i])
    i += 1
🎯 Mini Project: Shopping Cart Calculator
- Item names और prices list में store करें।
- Total price calculate करें।
- Discounts apply करें।
Tasks for practice:
  • List में 5 numbers डालिए और उनके squares print कीजिए।
  • While loop से 1 से 10 तक print कीजिए।
  • List में even numbers count कीजिए।
  • List के maximum और minimum number print कीजिए।
  • User से 5 numbers input लेकर total sum calculate कीजिए।

Day 12: Nested Loops and Patterns — Fun with Stars ⭐

Explanation: Loops के अंदर loops; Patterns बनाने में useful।

# Pyramid pattern
for i in range(1, 6):
    print("* " * i)
🎯 Mini Project: Pattern Printer
- Triangle, pyramid, reverse pyramid print करें
Tasks for practice:
  • Square pattern print कीजिए।
  • Right-angled triangle print कीजिए।
  • Pyramid pattern print कीजिए।
  • Reverse pyramid print कीजिए।
  • Number pyramid print कीजिए।

Day 13: List Comprehensions — Python’s Shortcut Magic

Explanation: List comprehension से concise और clean code लिखा जा सकता है।

even_numbers = [x for x in range(1, 21) if x % 2 == 0]
print(even_numbers)
🎯 Mini Task: 1 से 50 तक सभी even numbers एक line में list में generate करें।
Tasks for practice:
  • Squares of numbers 1–10 list में बनाएँ।
  • Odd numbers 1–20 list में बनाएँ।
  • Strings की list को uppercase में convert करें।
  • 1–10 के cubes list में बनाएँ।
  • 1–30 numbers में से 5 के multiples list में बनाएँ।

Day 14: Practice Day — Mini Quiz on Week 2 Topics

🎯 Challenge: 10 coding exercises for you

  • Exercise 1: एक list बनाइए और उसकी length print कीजिए।
  • Exercise 2: Tuple में एक item access कीजिए।
  • Exercise 3: Set में duplicates remove कीजिए।
  • Exercise 4: Dictionary में एक नया key-value add कीजिए।
  • Exercise 5: For loop से list print कीजिए।
  • Exercise 6: While loop से 1–10 print कीजिए।
  • Exercise 7: Nested loop से pattern print कीजिए।
  • Exercise 8: List comprehension से squares list बनाएँ।
  • Exercise 9: List में maximum number खोजिए।
  • Exercise 10: Dictionary से एक student delete कीजिए।
Previous Post Next Post

Contact Form