Module 4
Indexing
Accessing a single character by position.
Getting one character
You can access a single character of a string using its index: a number that indicates its position. You write the index in square brackets after the string.
Python
seq = "ATGC" print(seq[0]) print(seq[1])
→ A
T
1A
2T
3G
4C
Each box holds one character. len() counts them.
A common mistake
seq[1] gives the second character, not the first. This is because Python starts counting at zero.
Your task
Access by index
- Store ATGC and print the first character.