Deck 8: More About Strings
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/35
Play
Full screen (f)
Deck 8: More About Strings
1
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
Special = '0123456789'
Even = special[0:10:2]
A) '13579'
B) '2468'
C) '02468'
D) Invalid code
C
2
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
Special = '1357 Country Ln.'
S_string = special[ :4]
A) '7'
B) '1357'
C) '1357 '
D) Invalid code
B
3
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
String = 'Hello'
String += ' world'
A) 'Hello'
B) ' world'
C) 'Hello world'
D) Invalid code
C
4
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'
Special = '1357 Country Ln.'
S_string = special[-3: ]
A) '531'
B) 'Ln.'
C) ' Ln.'
D) '7531'
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
5
What is the first negative index in a string?
A) 0
B) -1
C) -0
D) Size of the string minus one
A) 0
B) -1
C) -0
D) Size of the string minus one
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
6
Invalid indexes do not cause slicing expressions to raise an exception.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
7
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']
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']
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
8
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
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
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
9
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.
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.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
10
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
A) 0 through 7
B) 0 through 8
C) -1 through -8
D) -1 through 6
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
11
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)
A) endswith(substring)
B) find(substring)
C) replace(string, substring)
D) startswith(substring)
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
12
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()
A) ischar()
B) isalpha()
C) istab()
D) isspace()
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
13
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
A) equal to
B) less than
C) greater than
D) not equal to
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
14
In slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
15
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
String = 'abcd'
String.upper()
A) 'abcd'
B) 'Abcd'
C) 'ABCD'
D) Invalid code
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
16
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.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
17
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
Special = '1357 Country Ln.'
S_string = special[4: ]
A) '1357'
B) 'Country Ln.'
C) ' Country Ln.'
D) Invalid code
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
18
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)
A) endswith(substring)
B) find(substring)
C) replace(string, substring)
D) startswith(substring)
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
19
Indexing works with both strings and lists.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
20
The index - 1 identifies the last character in a string.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
21
Each character in a string has a(n) _______________ which specifies its position in the string.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
22
When the operand on the left side of the * symbol is a string and the operand on the right side is an integer, it becomes the _______________ operator.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
23
A(n) _______________ exception will occur if you try to use an index that is out of range for a particular string.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
24
When accessing each character in a string, such as for copying purposes, you would typically use a while loop.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
25
A(n) _______________ is a span of characters that are taken from within a string.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
26
Strings are _______________, which means that once a string is created, it cannot be changed.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
27
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.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
28
An expression of the form string[i] = 'i' is a valid expression.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
29
The _______________ operator can be used to determine whether one string is contained in another string.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
30
The _______________ method returns the list of the words in the string.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
31
The third number in string slicing brackets represents the _______________ value.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
32
The _______________ method returns a copy of the string with all alphabetic letters converted to lower case.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
33
The strip() method returns a copy of the string with all leading whitespace characters removed, but does not remove trailing whitespace characters.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
34
The _______________ method returns true if the string contains only numeric digits.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
35
If the + operator is used on strings, it produces a string that is the combination of the two strings used as its operands.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck