Python Lists Explained: A Beginner's Guide (English & Hindi)

Python Lists: A Beginner's Guide

पाइथन लिस्ट्स: शुरुआती लोगों के लिए एक गाइड

A clear, bilingual guide to understanding one of Python's most powerful data structures.

पाइथन के सबसे शक्तिशाली डेटा स्ट्रक्चर्स में से एक को समझने के लिए एक स्पष्ट, द्विभाषी गाइड।

What is a Python List?

पाइथन लिस्ट क्या है?

A Python list is a fundamental data structure used to store a collection of items. Think of it like a shopping list where you can write down items, add new ones, cross them off, and change their order.

एक पाइथन लिस्ट एक मौलिक डेटा संरचना है जिसका उपयोग आइटम्स के संग्रह को स्टोर करने के लिए किया जाता है। इसे एक शॉपिंग लिस्ट की तरह समझें जहां आप आइटम्स लिख सकते हैं, नए जोड़ सकते हैं, उन्हें काट सकते हैं, और उनका क्रम बदल सकते हैं।

Key Properties / मुख्य गुण:

  • Ordered / क्रमबद्ध: Items have a defined order. / आइटम्स का एक निश्चित क्रम होता है।
  • Mutable / परिवर्तनशील: You can change, add, or remove items. / आप आइटम्स को बदल सकते हैं, जोड़ सकते हैं, या हटा सकते हैं।
  • Allows Duplicates & Mixed Types / डुप्लिकेट और मिश्रित प्रकार: Can contain duplicate items and different data types. / डुप्लिकेट आइटम और विभिन्न डेटा प्रकारों के आइटम हो सकते हैं।

Creating a List

लिस्ट बनाना

You create a list by placing comma-separated items inside square brackets `[]`.

आप स्क्वायर ब्रैकेट्स `[]` के अंदर कॉमा से अलग किए गए आइटम्स को रखकर एक लिस्ट बनाते हैं।

# A list of numbers (संख्याओं की एक लिस्ट)
my_numbers = [1, 2, 3, 4, 5]

# A list of strings (स्ट्रिंग्स की एक लिस्ट)
my_fruits = ["apple", "banana", "cherry"]

# An empty list (एक खाली लिस्ट)
empty_list = []

Accessing Items (Indexing)

आइटम्स को एक्सेस करना (इंडेक्सिंग)

Access an item by its index number. Indexing starts from `0` for the first item.

किसी आइटम को उसके इंडेक्स नंबर से एक्सेस करें। पहले आइटम के लिए इंडेक्सिंग `0` से शुरू होती है।

my_fruits = ["apple", "banana", "cherry"]

# First item (पहला आइटम)
print(my_fruits[0])  # Output: apple

# Last item (अंतिम आइटम)
print(my_fruits[-1]) # Output: cherry

Useful List Methods

उपयोगी लिस्ट मेथड्स

Python has many built-in methods to work with lists.

पाइथन में लिस्ट्स के साथ काम करने के लिए कई अंतर्निहित मेथड्स हैं।

Method (मेथड) Description (विवरण)
append() Adds an item to the end. (अंत में एक आइटम जोड़ता है।)
remove() Removes a specific item. (एक विशिष्ट आइटम को हटाता है।)
sort() Sorts the list. (लिस्ट को सॉर्ट करता है।)
len() Gets the number of items. (आइटम्स की संख्या बताता है।)

Happy Coding! / हैप्पी कोडिंग!

Comments

Popular posts from this blog

O-Level M1 + M2 Test Paper | NIELIT Practice

Introduction to Python Programming in IDLE: Beginners Guide | Python परिचय

IoT Part 3: How Smart Devices Talk (Communication Models)