String Indexing
Learn how to grab characters from Python strings using positive and negative indexes.
Sounds useful?
Jump into the interactive version.
No setup. No account. Just Python.
String Indexing
Learn how to grab characters from Python strings using positive and negative indexes.
Jump into the interactive version.
No setup. No account. Just Python.
This Block teaches you how to point at one specific character inside a Python string. You will start with simple examples like word[0], learn why Python starts counting from zero, and see how positive and negative indexes work in real code.
You will also learn the small but important traps: why word[len(word)] goes too far, what IndexError means, why empty strings have no valid indexes, and why spaces count as characters too.
What you will learn:
word[0]word[-1]len(word) - 1IndexErrorBy the end, you will be able to confidently pick the first, last, or any specific character from a string without guessing where Python is looking.
Ready to practice this in the browser?
> Play now