Starting Out with Python 2e Chapter 9 (Ch.8 question)
What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.' s_string = special[4: ] a. '1357' b. 'Country Ln.' c. ' Country Ln.' d. Invalid code
' Country Ln.'
What will be assigned to the string variable even after the execution of the following code? special = '0123456789' even = special[0:10:2] a. '13579' b. '2468' c. '02468' d. Invalid code
'02468'
What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.' s_string = special[ :4] a. '7' b. '1357' c. '1357 ' d. Invalid code
'1357'
What is the value of the variable string after the execution of the following code? string = 'abcd' string.upper() a. 'abcd' b. 'Abcd' c. 'ABCD' d. Invalid code
'ABCD'
What is the value of the variable string after the execution of the following code? string = 'Hello' string += ' world' a. 'Hello' b. ' world' c. 'Hello world' d. Invalid code
'Hello world'
What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.' s_string = special[-3: ] a. '531' b. 'Ln.' c. ' Ln.' d. '7531'
'Ln.'
What will be assigned to the string variable pattern after the execution of the following code? i = 3 pattern = 'z' * (5*i) a. 'zzzzzzzzzzzzzzz' b. 'zzzzz' c. Error: '*' operator used incorrectly d. The right side of the '*' must be an integer.
'zzzzzzzzzzzzzzz'
What is the first negative index in a string? a. 0 b. -1 c. -0 d. Size of the string minus one
-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
0 through 7
An expression of the form string[i] = 'i' is a valid expression.
False
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.
False
The strip() method returns a copy of the string with all leading whitespace characters removed, but does not remove trailing whitespace characters.
False
When accessing each character in a string, such as for copying purposes, you would typically use a while loop.
False
What is the return value of the string method lstrip()? a. The string with all whitespace removed b. The string with all leading spaces removed c. The string with all leading tabs removed d. The string with all leading whitespaces removed
The string with all leading whitespaces removed
If a whole paragraph is included in a single string, the split() method can be used to obtain a list of the sentences included in the paragraph.
True
If the + operator is used on strings, it produces a string that is the combination of the two strings used as its operands.
True
In slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead.
True
Indexing works with both strings and lists.
True
Invalid indexes do not cause slicing expressions to raise an exception.
True
The index - 1 identifies the last character in a string.
True
Which list will be referenced by the variable list_strip after the execution of the following code? list_string = '03/07/2008' list_strip = list_string.split('/') a. ['3', '7', '2008'] b. ['03', '07', '2008'] c. ['3', '/', '7', '/', '2008'] d. ['03', '/', '07', '/', '2008']
['03', '07', '2008']
Which method would you use to determine whether a substring is the suffix of a string? a. endswith(substring) b. find(substring) c. replace(string, substring) d. startswith(substring)
endswith(substring)
Which method would you use to determine whether a substring is present in a string? a. endswith(substring) b. find(substring) c. replace(string, substring) d. startswith(substring)
find(substring)
If the start index is_____the end index, the slicing expression will return an empty string. a. equal to b. less than c. greater than d. not equal to
greater than
Which of the following string methods can be used to determine if a string contains only '\n' characters? a. ischar() b. isalpha() c. istab() d. isspace()
isspace()