Skip to content

Oct 25: 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

  • PA 1 FlexDoko (modules + testing)
    • Part 1 utilities.py due TODAY (30 pts)
    • Part 2 game_logic.py due Friday 11/01 (60 pts)   extended
    • However, PA2 will begin Wed Oct 30, so don't procrastinate!
  • Read Ch 9 – ideally:
    • 1st half before Friday
    • 2nd half before Monday

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)