Skip to content

Nov 03: String Slicing, Methods

Learning Objectives

After today's class, you should be able to:

  • Explain the syntax and meaning of slice operations, with and without indexes.
  • Name four methods that strings provide, and describe what each method does.
  • Describe where to find the official documentation for methods of built-in types.

Reminders

POGIL Activity

  • Advanced Strings
    • If you are absent today, complete this activity at home
    • Bring your completed activity to class or office hours

Example Code

Model 1

dna = 'CTGACGACTT'
dna[5]
dna[10]
len(dna)
dna[:5]
dna[5:]
dna[5:10]
triplet = dna[2:5]
print(triplet)
dna[-5]
dna[-10]
dna[:-5]
dna[-5:]
triplet = dna[-4:-1]
print(triplet)

Model 2

dna = 'CTGACGACTT'
dna.lower()
print(dna)
lowercase = dna.lower()
print(lowercase)
dnalist = list(dna)
print(dnalist)
dnalist.reverse()
print(dnalist)
type(dna)
dna = dna.split('A')
print(dna)
type(dna)
dna.replace('C', 'g')
print(dna[0])
type(dna[0])
dna[0].replace('C', 'g')
print(dna)