Loading section...
String Indexing
Concepts: pyStringIndex
Every character in a string has a position number called an index. Python uses zero-based indexing, meaning the first character is at position 0, not position 1. This prints "P", "y", and "n". The characters are at positions 0, 1, and 5 respectively. Zero-Based Indexing Consider the string "Python". Here's how each character is indexed: The last character's index is always the string length minus 1. For a 6-character string, the last index is 5. Negative Indexing Python has a powerful feature: negative indices count from the end of the string. -1 is the last character, -2 is second to last, and so on. This prints "n", "o", and "P". Negative indexing makes it easy to access characters from the end without knowing the exact length. Index Out of Range Accessing an index that doesn't exist rai