Indexing in List :-
Python में Indexing in List का अर्थ है List में मौजूद elements की position (स्थिति) को index number के द्वारा identify करना और उस position पर मौजूद element को access करना।
List में indexing 0 से शुरू होती है। इसलिए पहला element 0 index पर, दूसरा element 1 index पर और इसी प्रकार आगे के elements store होते हैं।
English
Indexing in List means identifying the position of elements in a list using index numbers and accessing the element at a particular position.
Python uses zero-based indexing, so the first element has index 0, the second element has index 1, and so on.
Example:-
numbers = [10, 20, 30, 40, 50]
print(numbers[0])
print(numbers[2])
print(numbers[4])
Output:-
10
30
50
Because:-
यहाँ List के elements और उनके indexes हैं:
Element : 10 20 30 40 50
Index : 0 1 2 3 4
numbers[0] → 10
numbers[1] → 20
numbers[2] → 30
numbers[3] → 40
numbers[4] → 50
Important Point :-
Python में List की indexing 0 से शुरू होती है। इसलिए यदि List में 5 elements हैं, तो उनके positive indexes 0 से 4 तक होंगे।
यदि List में मौजूद index से बाहर का index access किया जाता है, तो Python IndexError देता है।
numbers = [10, 20, 30]
print(numbers[5])
यहाँ 5 index मौजूद नहीं है, इसलिए:
IndexError: list index out of range
Note: List में Negative Indexing भी होती है, जिसमें elements को right side से access किया जाता है। इसे अगले topic Negative Indexing में पढ़ेंगे।