All courses › Programming with Python › Strings and indexing
Strings and indexing
A string is a sequence of characters. Each character has an index starting at 0, and negative indices count backwards from . A slice s[i:j] gets the characters from index up to and including .
the character at index
slice from up to and including
the last character
Symbols
| a string (or list) | ||
| start and end index |
Example
s = "robotikk"
s[2:6] gives "boti" (indices 2, 3, 4, 5).
s[-1] gives "k".
The length of
Practise python basics for free →
s[i:j] is — the last index is never included.← Numbers and types · Lists →