Download presentation
Presentation is loading. Please wait.
1
CEV208 Computer Programming
Strings Spring 2013
2
A string is a sequence A string is a sequence of characters. index
(its value has to be an integer) index (its value has to be an integer) Careful!:
3
len len is a built-in function that returns the number of characters in a string.
4
Traversal Traversal: Processing a string one character at a time.
A traversal with a while loop: A traversal with a for loop:
5
Assignment
6
Traversal What is the output of this program?
7
String slices slice: a segment of a string
8
String slices
9
Strings are immutable object : Assume that it is the same thing as a value for now. item : One of the values in a sequence.
10
Searching Search: Traversing a sequence and returning when we find what we are looking for.
11
Counter ASSIGNMENT:
12
string methods method: similar to a function, but the syntax is different. invocation: a call to a method. method upper takes a string and returns a new string with all uppercase letters: method find: method count:
13
The in operator What does this function do?
14
String comparison The relational operators work on strings.
You may use the other relational operators for putting words in alphabetical order: CAREFUL!: In Python, all the uppercase letters come before all the lowercase letters.
15
Debugging This function contains two errors:
16
Debugging
17
Glossary object immutable sequence traverse item search index counter
slice method empty string invocation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.