Concept
Grabbing Letters by Index [0]
Computers count starting at 0, not 1. Every letter in a string has an address starting from zero inside square brackets `[]`:
python
word = "PYTHON"
print(word[0]) # 'P' (first letter)
print(word[1]) # 'Y' (second letter)# 30. Grabbing Letters by Index [0] Computers count starting at 0, not 1. Every letter in a string has an address starting from zero inside square brackets `[]`: ```python word = "PYTHON" print(word[0]) # 'P' (first letter) print(word[1]) # 'Y' (second letter) ``` Ask for an index that doesn't exist (like `word[99]`), and Python halts with `IndexError`.
Checkpoint
In `pet = "CAT"`, what letter lives at `pet[0]`?
Practice
Create `code = "ROBOT"` and print the very first letter using `[0]`.
01
Tap code blocks below to assemble
Available Blocks