Understanding Sequences of Characters in Computer Science: A Guide to Strings
80 likes | 196 Vues
This introduction to computer science discusses strings as sequences of characters, exploring the manipulation of data sequences. Learn about string properties, indexing, slicing, reversing, appending, and more.
Understanding Sequences of Characters in Computer Science: A Guide to Strings
E N D
Presentation Transcript
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
Sequences of data • Can work with size of sequence • Can work with individual pieces of information in the sequence
Thought Exercise • Suppose I give you a string >>> mesg = “Today is Wednesday” • What is the length of that string?
Thought Exercise >>> mesg = “Today is Wednesday” • mesg[1] • mesg[11] • mesg[-1] • mesg[3:9] • mesg[15:]
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
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 functions and handling only one case