TRUE/FALSE
1. You cannot use a for loop to iterate over the characters in a string.
ANS: F
2. Indexing works with both strings and lists.
ANS: T
3. In slicing, if the end index specifies a position beyond the end of the string, Python will use the length
of the string instead.
ANS: T
4. Indexing of a string starts at 1 so the index of the first character is 1, the index of the second character
is 2, and so forth.
ANS: F
5. The index -1 identifies the last character of a string.
ANS: T
6. The following expression is valid:
string[i] = 'i'
ANS: F
7. The following code will display 'yes + no':
mystr = 'yes'
yourstr = 'no'
mystr += yourstr
print(mystr)
ANS: F
8. If the + operator is used on strings, it produces a string that is a combination of the two strings used as
its operands.
ANS: T
9. When accessing each character in a string, such as for copying purposes, you would typically use a
while loop.
51
, Chapter 8 More About Strings
ANS: F
10. If a whole paragraph is included in a single string, the split() method can be used to obtain a list of
the sentences in the paragraph.
ANS: T
11. The strip() method returns a copy of the string with all the leading whitespace characters removed
but does not remove trailing whitespace characters.
ANS: F
MULTIPLE CHOICE
1. What are the valid indexes for the string 'New York'?
a. 0 through 7
b. 0 through 8
c. -1 through -8
d. -1 through 6
ANS: A
2. What will be displayed after the following code executes?
mystr = 'yes'
yourstr = 'no'
mystr += yourstr * 2
print(mystr)
a. yes + no * 2
b. yes + no yes + no
c. yesnono
d. yesnoyesno
ANS: C
3. What will be assigned to the variable s_string after the following code executes?
special = '1357 Country Ln.'
s_string = special[ :4]
a. '7'
b. '1357'
c. 5
d. '7 Country Ln.'
ANS: B
4. What will be assigned to the variable s_string after the following code executes?
special = '1357 Country Ln.'
52