Thinking about Strings
Intro to Computer Science
CS1510, Section 2
Dr. Sarah Diesburg
What are strings?
Sequences of characters
We will often work with sequences of data
String is just a specific example
We will see many of the things we do with
strings later on with other sequences of data
2
Sequences of data
Can work with size of sequence
Can work with individual pieces of information
in the sequence
3
Thought Exercise
Suppose I give you a string
>>> mesg = “Today is Friday”
What is the length of that string?
4
Thought Exercise
>>> mesg = “Today is Friday”
mesg[1]
mesg[11]
mesg[-1]
mesg[3:9]
mesg[10:]
mesg[10:37]
5
Note about Answers
>>> msg[3:9]
Answer is
ay is
But how do we write this to show spaces?
On answer sheets or tests, be very careful
If I can’t tell that there are spaces, I might take
points off
6
Questions so far?
7
Let’s talk about the lab
Sequences, indexes, and slicing.
Reversing the Str
Working backwards and appending
Working forwards and prepending
Counting the vowels
Handling both cases
Using methods and handling only one case