Introduction To Programming - Chapter 8

25 July 2022
4.7 (114 reviews)
25 test answers

Unlock all answers in this set

Unlock answers (21)
question
a. 0 through 7
answer
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
question
b. '1357'
answer
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
question
c. ' Country Ln.'
answer
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
question
c. '02468'
answer
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
question
b. 'Ln.'
answer
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'
question
c. greater than
answer
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
question
d. isspace()
answer
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()
question
d. The string with all leading whitespaces removed
answer
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
question
a. 'zzzzzzzzzzzzzzz'
answer
What will be assigned to the string variable pattern after the execution of the following code? i = 3 pattern = z x (5 x i) a. 'zzzzzzzzzzzzzzz' b. 'zzzzz' c. Error: '*' operator used incorrectly d. The right side of the '*' must be an integer
question
b. ['03', '07', '2008']
answer
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']
question
b. -1
answer
What is the first negative index in a string? a. 0 b. -1 c. -0 d. Size of the string minus one
question
b. find(substring)
answer
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)
question
a. endswith(substring)
answer
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)
question
c. 'ABCD'
answer
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
question
c. 'Hello world'
answer
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
question
True
answer
True/False: Invalid indexes do not cause slicing expressions to raise an exception.
question
True
answer
True/False: Indexing works with both strings and lists.
question
False
answer
True/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.
question
True
answer
True/False: The index - 1 identifies the last character in a string.
question
True
answer
True/False: In slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead.
question
False
answer
True/False: An expression of the form string[i] = 'i' is a valid expression.
question
True
answer
True/False: If the + operator is used on strings, it produces a string that is the combination of the two strings used as its operands.
question
False
answer
True/False: When accessing each character in a string, such as for copying purposes, you would typically use a while loop.
question
True
answer
True/False: 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.
question
False
answer
True/False: The strip() method returns a copy of the string with all leading whitespace characters removed, but does not remove trailing whitespace characters.