Discover how a simple number can unlock any letter in your text instantly!
Why String indexing (positive and negative) in Python? - Purpose & Use Cases
Imagine you have a long sentence and you want to find a specific letter or word inside it. Without a simple way to point to each letter, you might have to count every character by hand from the start every time.
Counting letters manually is slow and easy to mess up. If you want the last letter, you have to count the whole sentence backward, which is confusing and wastes time.
String indexing lets you quickly grab any letter by its position. Positive numbers count from the start, and negative numbers count from the end, so you can easily get letters without counting manually.
text = 'hello' # To get last letter manually: last = text[len(text)-1]
text = 'hello' last = text[-1]
It makes finding and using parts of text fast and simple, like picking fruits from a basket by their position.
When typing a password, you might want to check the first and last characters quickly to meet rules. String indexing helps you do that easily.
String indexing lets you access letters by position.
Positive indexes start from the beginning (0, 1, 2...).
Negative indexes start from the end (-1, -2, -3...).