Module 4
Slicing
Extracting a portion of a string.
Taking a slice
You can extract a portion of a string using slicing. You specify a start index and a stop index, separated by a colon.
Python
seq = "ATGCGTA" print(seq[0:3]) print(seq[3:6])
→ ATG
CGT
The slice starts at the first index and goes up to, but not including, the second. seq[0:3] gives characters at positions 0, 1, and 2.
Your task
Slice a string
- Store ATGCGTA and print the first three characters.