Indexing in Python Strings :-
Indexing (इंडेक्सिंग) वह प्रक्रिया है जिसके द्वारा String (स्ट्रिंग) के प्रत्येक Character (अक्षर) को उसकी Position (स्थिति) के आधार पर Access (प्राप्त) किया जाता है।
Python में String एक Sequence (क्रम) होती है, इसलिए उसके प्रत्येक Character का एक Index Number (इंडेक्स संख्या) होता है। Index की सहायता से हम किसी भी Character को आसानी से प्राप्त कर सकते हैं।
Python में Indexing 0 (शून्य) से शुरू होती है। अर्थात् पहला Character हमेशा Index 0 पर होता है।
English
Indexing is the process of accessing individual characters of a string using their position (index).
Since a string is a sequence of characters, every character has a unique index number. Using these index numbers, we can access any character in the string.
In Python, indexing starts from 0, so the first character is always at index 0.
Syntax (सिंटैक्स)-
string_name[index]
Example -
Python में दो प्रकार की Indexing होती है:
Positive Indexing (धनात्मक इंडेक्सिंग) वह विधि (Method) है जिसमें String (स्ट्रिंग) के Characters (अक्षरों) को बाएँ (Left) से दाएँ (Right) की ओर Index Number (इंडेक्स संख्या) प्रदान की जाती है।
Python में Positive Indexing हमेशा 0 (शून्य) से शुरू होती है। अर्थात् String का पहला Character Index 0 पर, दूसरा Character Index 1 पर, तीसरा Character Index 2 पर होता है।
Positive Indexing का उपयोग किसी String के किसी विशेष Character को उसकी Position (स्थिति) के आधार पर Access (प्राप्त) करने के लिए किया जाता है।
EnglishPositive Indexing is a method of assigning index numbers to the characters of a string from left to right.
In Python, positive indexing always starts from 0. This means the first character is at index 0, the second character is at index 1, and so on.
Positive indexing is used to access a specific character in a string based on its position.
Example -
यदि दिया गया Positive Index String की Length से बड़ा हो, तो IndexError आता है।
हम len() Function की सहायता से अंतिम Character प्राप्त कर सकते हैं।
Negative Indexing (ऋणात्मक इंडेक्सिंग) वह विधि (Method) है जिसमें String (स्ट्रिंग) के Characters (अक्षरों) को दाएँ (Right) से बाएँ (Left) की ओर Index Number (इंडेक्स संख्या) प्रदान की जाती है।
Python में अंतिम (Last) Character का Index हमेशा -1 होता है। उससे पहले वाले Character का Index -2, फिर -3, और इसी प्रकार आगे बढ़ता है।
Negative Indexing का उपयोग विशेष रूप से तब किया जाता है जब हमें String के अंत (End) से Characters को Access (प्राप्त) करना हो।
EnglishNegative Indexing is a method of assigning index numbers to the characters of a string from right to left.
In Python, the last character of a string always has the index -1. The second last character has the index -2, the third last has -3, and so on.
Negative indexing is mainly used when we want to access characters from the end of a string.
Example-